mirror of https://github.com/rails/rails
Fix DebugExceptions crash on nil Exception#annoted_source_code
The issue was reported in #29537. We expect Exception#annoted_source_code to return an `Array`, but this contract may not be followed by all the implementers. Fixes #29537.
This commit is contained in:
parent
3c7c2d220e
commit
7465b383ea
|
@ -134,6 +134,7 @@ module ActionDispatch
|
|||
|
||||
def log_error(request, wrapper)
|
||||
logger = logger(request)
|
||||
|
||||
return unless logger
|
||||
|
||||
exception = wrapper.exception
|
||||
|
@ -152,10 +153,14 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def log_array(logger, array)
|
||||
lines = Array(array)
|
||||
|
||||
return if lines.empty?
|
||||
|
||||
if logger.formatter && logger.formatter.respond_to?(:tags_text)
|
||||
logger.fatal array.join("\n#{logger.formatter.tags_text}")
|
||||
logger.fatal lines.join("\n#{logger.formatter.tags_text}")
|
||||
else
|
||||
logger.fatal array.join("\n")
|
||||
logger.fatal lines.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,6 +20,12 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
|
|||
class Boomer
|
||||
attr_accessor :closed
|
||||
|
||||
class NilAnnotedSourceCodeError < StandardError
|
||||
def annoted_source_code
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(detailed = false)
|
||||
@detailed = detailed
|
||||
@closed = false
|
||||
|
@ -48,6 +54,10 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
def method_that_raises_nil_annoted_source_code
|
||||
raise NilAnnotedSourceCodeError, "nil annoted_source_code"
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env["action_dispatch.show_detailed_exceptions"] = @detailed
|
||||
req = ActionDispatch::Request.new(env)
|
||||
|
@ -106,6 +116,8 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
|
|||
raise_nested_exceptions
|
||||
when %r{/actionable_error}
|
||||
raise CustomActionableError
|
||||
when %r{/nil_annoted_source_code_error}
|
||||
method_that_raises_nil_annoted_source_code
|
||||
else
|
||||
raise "puke!"
|
||||
end
|
||||
|
@ -662,4 +674,16 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
|
|||
assert_response 400
|
||||
assert_match "ActionController::BadRequest", body
|
||||
end
|
||||
|
||||
test "debug exceptions with misbehaving Exception#annoted_source_code" do
|
||||
@app = DevelopmentApp
|
||||
|
||||
io = StringIO.new
|
||||
logger = ActiveSupport::Logger.new(io)
|
||||
|
||||
get "/nil_annoted_source_code_error", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => logger }
|
||||
|
||||
assert_select "header h1", /DebugExceptionsTest::Boomer::NilAnnotedSourceCodeError/
|
||||
assert_select "#container h2", /nil annoted_source_code/
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue