psych icon indicating copy to clipboard operation
psych copied to clipboard

Dumping and loading an Exception loses the backtrace information.

Open Fryguy opened this issue 12 years ago • 1 comments

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

Fryguy avatar Sep 29 '12 02:09 Fryguy

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

jeffshantz avatar Feb 26 '19 17:02 jeffshantz