未验证 提交 ff756e52 编写于 作者: R Rafael Mendonça França

Merge pull request #29538 from gsamokovarov/fix-exceptions-with-nil-annoted-source-code

Fix DebugExceptions crash on nil Exception#annoted_source_code
......@@ -134,6 +134,7 @@ def render(status, body, format)
def log_error(request, wrapper)
logger = logger(request)
return unless logger
exception = wrapper.exception
......@@ -152,10 +153,14 @@ def log_error(request, wrapper)
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 CustomActionableError < StandardError
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 @@ def raise_nested_exceptions
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 @@ def call(env)
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 @@ def call(env)
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册