Log trace of causes for unhandled exceptions
This commit is contained in:
parent
827f4ef15c
commit
f47ef36c4d
@ -142,17 +142,30 @@ def log_error(request, wrapper)
|
|||||||
|
|
||||||
message = []
|
message = []
|
||||||
message << " "
|
message << " "
|
||||||
message << "#{wrapper.exception_class_name} (#{wrapper.message}):"
|
|
||||||
if wrapper.has_cause?
|
if wrapper.has_cause?
|
||||||
message << "\nCauses:"
|
message << "#{wrapper.exception_class_name} (#{wrapper.message})"
|
||||||
wrapper.wrapped_causes.each do |wrapped_cause|
|
wrapper.wrapped_causes.each do |wrapped_cause|
|
||||||
message << "#{wrapped_cause.exception_class_name} (#{wrapped_cause.message})"
|
message << "Caused by: #{wrapped_cause.exception_class_name} (#{wrapped_cause.message})"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
message << "\nInformation for: #{wrapper.exception_class_name} (#{wrapper.message}):"
|
||||||
|
else
|
||||||
|
message << "#{wrapper.exception_class_name} (#{wrapper.message}):"
|
||||||
end
|
end
|
||||||
|
|
||||||
message.concat(wrapper.annotated_source_code)
|
message.concat(wrapper.annotated_source_code)
|
||||||
message << " "
|
message << " "
|
||||||
message.concat(trace)
|
message.concat(trace)
|
||||||
|
|
||||||
|
if wrapper.has_cause?
|
||||||
|
wrapper.wrapped_causes.each do |wrapped_cause|
|
||||||
|
message << "\nInformation for cause: #{wrapped_cause.exception_class_name} (#{wrapped_cause.message}):"
|
||||||
|
message.concat(wrapped_cause.annotated_source_code)
|
||||||
|
message << " "
|
||||||
|
message.concat(wrapped_cause.exception_trace)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
log_array(logger, message, request)
|
log_array(logger, message, request)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -627,11 +627,43 @@ def self.build_app(app, *args)
|
|||||||
get "/nested_exceptions", headers: env
|
get "/nested_exceptions", headers: env
|
||||||
assert_response 500
|
assert_response 500
|
||||||
log = output.rewind && output.read
|
log = output.rewind && output.read
|
||||||
assert_includes log, <<~MSG
|
|
||||||
Causes:
|
# Splitting into paragraphs to be easier to see difference/error when there is one
|
||||||
RuntimeError (Second error)
|
paragraphs = log.split(/\n\s*\n/)
|
||||||
RuntimeError (First error)
|
|
||||||
|
assert_includes(paragraphs[0], <<~MSG.strip)
|
||||||
|
RuntimeError (Third error)
|
||||||
|
Caused by: RuntimeError (Second error)
|
||||||
|
Caused by: RuntimeError (First error)
|
||||||
MSG
|
MSG
|
||||||
|
|
||||||
|
assert_includes(paragraphs[1], <<~MSG.strip)
|
||||||
|
Information for: RuntimeError (Third error):
|
||||||
|
MSG
|
||||||
|
|
||||||
|
assert_match Regexp.new(<<~REGEX.strip), paragraphs[2].lines[0..2].join
|
||||||
|
\\A.*in `rescue in rescue in raise_nested_exceptions'
|
||||||
|
.*in `rescue in raise_nested_exceptions'
|
||||||
|
.*in `raise_nested_exceptions'
|
||||||
|
REGEX
|
||||||
|
|
||||||
|
assert_includes(paragraphs[3], <<~MSG.strip)
|
||||||
|
Information for cause: RuntimeError (Second error):
|
||||||
|
MSG
|
||||||
|
|
||||||
|
assert_match Regexp.new(<<~REGEX.strip), paragraphs[4].lines[0..1].join
|
||||||
|
\\A.*in `rescue in raise_nested_exceptions'
|
||||||
|
.*in `raise_nested_exceptions'
|
||||||
|
REGEX
|
||||||
|
|
||||||
|
|
||||||
|
assert_includes(paragraphs[5], <<~MSG.strip)
|
||||||
|
Information for cause: RuntimeError (First error):
|
||||||
|
MSG
|
||||||
|
|
||||||
|
assert_match Regexp.new(<<~REGEX.strip), paragraphs[6].lines[0]
|
||||||
|
\\A.*in `raise_nested_exceptions'
|
||||||
|
REGEX
|
||||||
end
|
end
|
||||||
|
|
||||||
test "display backtrace when error type is SyntaxError" do
|
test "display backtrace when error type is SyntaxError" do
|
||||||
|
Loading…
Reference in New Issue
Block a user