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.
attempting to pass caller_location to Kernel#raise in the test method fails with bla.rb:2:in `set_backtrace': backtrace must be Array of String (TypeError)
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
+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).
I think both Kernel#raise and Exception#set_backtrace would need to accept array of Thread::Backtrace::Location.
That's an idea I fully support. Although when I need to modify an error's backtrace 95% of the time it's because I want to skip the first few frames, like raise Error, "message", caller[3..-1]. So it would be nice to have a shortcut idiom for this, like perhaps raise Error, "message", skip: 3