Merge pull request #50764 from eugeneius/syntax_error_proxy_nil_backtrace_locations

Handle nil backtrace_locations in SyntaxErrorProxy
This commit is contained in:
Eugene Kenny 2024-01-16 14:20:13 +00:00 committed by GitHub
commit 0656787be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

@ -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__

@ -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)