Skip to content

Commit 0656787

Browse files
authored
Merge pull request rails#50764 from eugeneius/syntax_error_proxy_nil_backtrace_locations
Handle nil backtrace_locations in SyntaxErrorProxy
2 parents 4fa50ba + 16d1351 commit 0656787

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

actionpack/test/dispatch/exception_wrapper_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ def backtrace
8383
end
8484
end
8585

86+
test "#source_extracts works with nil backtrace_locations" do
87+
exception = begin eval "class Foo; yield; end"; rescue SyntaxError => ex; ex; end
88+
89+
wrapper = ExceptionWrapper.new(nil, exception)
90+
91+
assert_empty wrapper.source_extracts
92+
end
93+
8694
if defined?(ErrorHighlight) && Gem::Version.new(ErrorHighlight::VERSION) >= Gem::Version.new("0.4.0")
8795
test "#source_extracts works with error_highlight" do
8896
lineno = __LINE__

activesupport/lib/active_support/syntax_error_proxy.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def spot(_)
3232
end
3333

3434
def backtrace_locations
35+
return nil if super.nil?
36+
3537
parse_message_for_trace.map { |trace|
3638
file, line = trace.match(/^(.+?):(\d+).*$/, &:captures) || trace
3739
BacktraceLocation.new(file, line.to_i, trace)

0 commit comments

Comments
 (0)