Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nil backtrace_locations in SyntaxErrorProxy #50764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions actionpack/test/dispatch/exception_wrapper_test.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def spot(_)
end

def backtrace_locations
return nil if super.nil?
byroot marked this conversation as resolved.
Show resolved Hide resolved

parse_message_for_trace.map { |trace|
file, line = trace.match(/^(.+?):(\d+).*$/, &:captures) || trace
BacktraceLocation.new(file, line.to_i, trace)
Expand Down