Skip to content

Commit 4fc2df2

Browse files
committed
Include exception causes into log messages
1 parent e7ea111 commit 4fc2df2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

actionpack/lib/action_dispatch/middleware/debug_exceptions.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def log_error(request, wrapper)
141141
message = []
142142
message << " "
143143
message << "#{wrapper.exception_class_name} (#{wrapper.message}):"
144+
if wrapper.has_cause?
145+
message << "\nCauses:"
146+
wrapper.wrapped_causes.each do |wrapped_cause|
147+
message << "#{wrapped_cause.exception_class_name} (#{wrapped_cause.message})"
148+
end
149+
end
144150
message.concat(wrapper.annotated_source_code)
145151
message << " "
146152
message.concat(trace)

actionpack/test/dispatch/debug_exceptions_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,25 @@ def self.build_app(app, *args)
615615
assert_not_empty (output.rewind && output.read).lines
616616
end
617617

618+
test "logs exception causes" do
619+
@app = DevelopmentApp
620+
621+
output = StringIO.new
622+
623+
env = { "action_dispatch.show_exceptions" => :all,
624+
"action_dispatch.logger" => Logger.new(output),
625+
"action_dispatch.log_rescued_responses" => true }
626+
627+
get "/nested_exceptions", headers: env
628+
assert_response 500
629+
log = output.rewind && output.read
630+
assert_includes log, <<~MSG
631+
Causes:
632+
RuntimeError (Second error)
633+
RuntimeError (First error)
634+
MSG
635+
end
636+
618637
test "display backtrace when error type is SyntaxError" do
619638
@app = DevelopmentApp
620639

0 commit comments

Comments
 (0)