Skip to content

Commit

Permalink
Merge pull request puma#955 from jf/add-request-info-to-standard-erro…
Browse files Browse the repository at this point in the history
…r-rescue

Add request info to standard error rescue
  • Loading branch information
evanphx committed Apr 22, 2016
2 parents 17b1ca6 + d76e612 commit 9ad34ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions lib/puma/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ def ssl_error(server, peeraddr, peercert, error)
end

# An unknown error has occurred.
# +server+ is the Server object, +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")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puma/server.rb
Original file line number Diff line number Diff line change
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

0 comments on commit 9ad34ec

Please sign in to comment.