psych
psych copied to clipboard
Dumping and loading an Exception loses the backtrace information.
Dumping and loading an Exception loses the backtrace information. The following test demonstrates this.
def test_exception_should_have_backtrace
err = 1 / 0 rescue $!
assert_not_nil err.backtrace
assert_not_nil YAML.load(YAML.dump(err)).backtrace
end
This surfaced for me when attempting to mail an exception to myself using delayed_job. I initially thought it was delayed_job stripping out the backtrace, but a simple test in the Rails console reveals that's not the case:
begin
raise "Test"
rescue => ex
puts YAML::dump(ex)
end
Output:
--- !ruby/exception:RuntimeError
message: Test