File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ module CoreExt
55 private def generate_snippet
66 if ArgumentError === self && message =~ /\A (?:wrong number of arguments|missing keyword[s]?|unknown keyword[s]?|no keywords accepted)\b /
77 locs = self . backtrace_locations
8- return "" if locs . size < 2
8+ return "" if locs . nil? || locs . size < 2
99 callee_loc , caller_loc = locs
1010 callee_spot = ErrorHighlight . spot ( self , backtrace_location : callee_loc , point_type : :name )
1111 caller_spot = ErrorHighlight . spot ( self , backtrace_location : caller_loc , point_type : :name )
Original file line number Diff line number Diff line change @@ -1815,6 +1815,30 @@ def test_detailed_message_does_not_raise_when_argument_error_is_rewrapped
18151815 end
18161816 end
18171817
1818+ def test_detailed_message_does_not_raise_when_backtrace_locations_is_nil
1819+ # This reproduces a real-world crash: when an exception crosses a process
1820+ # boundary via Marshal, `backtrace` survives as strings but
1821+ # `backtrace_locations` becomes nil. A keyword ArgumentError then crashed
1822+ # CoreExt#generate_snippet with `undefined method 'size' for nil`.
1823+ begin
1824+ def_with_required_keyword
1825+ rescue ArgumentError => original
1826+ exc = Marshal . load ( Marshal . dump ( original ) )
1827+ end
1828+
1829+ assert_nil exc . backtrace_locations
1830+
1831+ msg = nil
1832+ assert_nothing_raised do
1833+ msg = exc . detailed_message ( highlight : false )
1834+ end
1835+ assert_match ( "missing keyword" , msg )
1836+
1837+ assert_nothing_raised do
1838+ exc . full_message ( highlight : false )
1839+ end
1840+ end
1841+
18181842 private
18191843
18201844 def find_node_by_id ( node , node_id )
You can’t perform that action at this time.
0 commit comments