def unmarshal_and_raise_errors(channel, print_exception = nil, app_type = "rails")
args = channel.read
if args.nil?
raise EOFError, "Unexpected end-of-file detected."
end
status = args[0]
if status == 'exception'
child_exception = unmarshal_exception(channel.read_scalar)
stderr = channel.read_scalar
exception = AppInitError.new(
"Application '#{@app_root}' raised an exception: " <<
"#{child_exception.class} (#{child_exception.message})",
child_exception,
app_type,
stderr.empty? ? nil : stderr)
elsif status == 'exit'
child_exception = unmarshal_exception(channel.read_scalar)
stderr = channel.read_scalar
exception = AppInitError.new("Application '#{@app_root}' exited during startup",
child_exception, app_type, stderr.empty? ? nil : stderr)
else
exception = nil
end
if print_exception && exception
if print_exception.respond_to?(:puts)
print_exception(self.class.to_s, child_exception, print_exception)
elsif print_exception.respond_to?(:to_str)
filename = print_exception.to_str
File.open(filename, 'a') do |f|
print_exception(self.class.to_s, child_exception, f)
end
else
print_exception(self.class.to_s, child_exception)
end
end
raise exception if exception
end