Skip to content

Commit

Permalink
Merge pull request #50764 from eugeneius/syntax_error_proxy_nil_backt…
Browse files Browse the repository at this point in the history
…race_locations

Handle nil backtrace_locations in SyntaxErrorProxy
  • Loading branch information
eugeneius committed Jan 16, 2024
1 parent b02f6c9 commit 894f933
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions actionpack/test/dispatch/exception_wrapper_test.rb
Expand Up @@ -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__
Expand Down
2 changes: 2 additions & 0 deletions activesupport/lib/active_support/syntax_error_proxy.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 894f933

Please sign in to comment.