diff --git a/actionpack/test/dispatch/exception_wrapper_test.rb b/actionpack/test/dispatch/exception_wrapper_test.rb index 7f96ea048a07b..898084d0e3507 100644 --- a/actionpack/test/dispatch/exception_wrapper_test.rb +++ b/actionpack/test/dispatch/exception_wrapper_test.rb @@ -83,6 +83,14 @@ def backtrace end end + test "#source_extracts works with nil backtrace_locations" do + exception = begin eval "class Foo; yield; end"; rescue SyntaxError => ex; ex; end + + wrapper = ExceptionWrapper.new(nil, exception) + + assert_empty wrapper.source_extracts + end + if defined?(ErrorHighlight) && Gem::Version.new(ErrorHighlight::VERSION) >= Gem::Version.new("0.4.0") test "#source_extracts works with error_highlight" do lineno = __LINE__ diff --git a/activesupport/lib/active_support/syntax_error_proxy.rb b/activesupport/lib/active_support/syntax_error_proxy.rb index 87eaca4376fe9..08baf2f0279a3 100644 --- a/activesupport/lib/active_support/syntax_error_proxy.rb +++ b/activesupport/lib/active_support/syntax_error_proxy.rb @@ -32,6 +32,8 @@ def spot(_) end def backtrace_locations + return nil if super.nil? + parse_message_for_trace.map { |trace| file, line = trace.match(/^(.+?):(\d+).*$/, &:captures) || trace BacktraceLocation.new(file, line.to_i, trace)