Project

General

Profile

Feature #13557

there's no way to pass backtrace locations as a massaged backtrace

Added by sylvain.joyeux (Sylvain Joyeux) over 2 years ago. Updated 3 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:81102]

Description

When re-raising exceptions, it is sometimes useful to "massage" the backtrace (especially in DSLs).

There is currently no way to do it using only backtrace locations. This causes the new exception to have #backtrace_locations return nil, and thus makes backtrace_locations unreliable as a whole.

Example:

def test
    raise ArgumentError, "", caller_locations
end

begin
    test
rescue ArgumentError => e
    p e.backtrace_locations
end

attempting to pass caller_location to Kernel#raise in the test method fails with bla.rb:2:inset_backtrace': backtrace must be Array of String (TypeError)`

History

Updated by sylvain.joyeux (Sylvain Joyeux) over 2 years ago

Did a mistake. The code example uses caller_locations (and therefore causes the TypeError exception) while I meant it to use caller and therefore cause e.backtrace_locations to be nil

Updated by Eregon (Benoit Daloze) over 2 years ago

+1 This would be a nice feature and let the VM still keep the backtrace information in an flexible way (instead of dumping it to a String like Exception#backtrace).

#3

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

  • Backport deleted (2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN)
  • ruby -v deleted (ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux], ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux])
  • Tracker changed from Bug to Feature

Also available in: Atom PDF