Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add request info to standard error rescue #955

Merged
merged 3 commits into from Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/puma/events.rb
Expand Up @@ -106,15 +106,21 @@ def ssl_error(server, peeraddr, peercert, error)
end

# An unknown error has occurred.
# +server+ is the Server object, +env+ the request, +error+ an exception
# object, and +kind+ some additional info.
# +server+ is the Server object, +error+ an exception object,
# +kind+ some additional info, and +env+ the request.
#
def unknown_error(server, error, kind="Unknown")
def unknown_error(server, error, kind="Unknown", env=nil)
if error.respond_to? :render
error.render "#{Time.now}: #{kind} error", @stderr
else
@stderr.puts "#{Time.now}: #{kind} error: #{error.inspect}"
@stderr.puts error.backtrace.join("\n")
if env
string_block = [ "#{Time.now}: #{kind} error handling request { #{env['REQUEST_METHOD']} #{env['PATH_INFO']} }" ]
string_block << error.inspect
else
string_block = [ "#{Time.now}: #{kind} error: #{error.inspect}" ]
end
string_block << error.backtrace
@stderr.puts string_block.join("\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer you just call @stderr.puts multiple times rather than make an array and then join it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer multiple calls too. Sorry for not elaborating; the only reason I did a single call is so that there wont be the possibility (?) of other output from other @stderr.puts calls being interleaved among these debug lines. Do you think this is a valid concern / makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any comments, @evanphx ? Would appreciate your input on this.

end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puma/server.rb
Expand Up @@ -588,7 +588,7 @@ def handle_request(req, lines)
res_body = ["Request was internally terminated early\n"]

rescue StandardError => e
@events.unknown_error self, e, "Rack app"
@events.unknown_error self, e, "Rack app", env

status, headers, res_body = lowlevel_error(e, env)
end
Expand Down