Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/error_highlight/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module CoreExt
private def generate_snippet
if ArgumentError === self && message =~ /\A(?:wrong number of arguments|missing keyword[s]?|unknown keyword[s]?|no keywords accepted)\b/
locs = self.backtrace_locations
return "" if locs.size < 2
return "" if locs.nil? || locs.size < 2
callee_loc, caller_loc = locs
callee_spot = ErrorHighlight.spot(self, backtrace_location: callee_loc, point_type: :name)
caller_spot = ErrorHighlight.spot(self, backtrace_location: caller_loc, point_type: :name)
Expand Down
24 changes: 24 additions & 0 deletions test/test_error_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,30 @@ def test_detailed_message_does_not_raise_when_argument_error_is_rewrapped
end
end

def test_detailed_message_does_not_raise_when_backtrace_locations_is_nil
# This reproduces a real-world crash: when an exception crosses a process
# boundary via Marshal, `backtrace` survives as strings but
# `backtrace_locations` becomes nil. A keyword ArgumentError then crashed
# CoreExt#generate_snippet with `undefined method 'size' for nil`.
begin
def_with_required_keyword
rescue ArgumentError => original
exc = Marshal.load(Marshal.dump(original))
end

assert_nil exc.backtrace_locations

msg = nil
assert_nothing_raised do
msg = exc.detailed_message(highlight: false)
end
assert_match("missing keyword", msg)

assert_nothing_raised do
exc.full_message(highlight: false)
end
end

private

def find_node_by_id(node, node_id)
Expand Down