1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Round trip exception backtraces

This commit allows exception backtraces to round trip
This commit is contained in:
Aaron Patterson 2019-01-09 13:34:51 -08:00 committed by Hiroshi SHIBATA
parent f770a5be66
commit a53ab897c3
3 changed files with 19 additions and 0 deletions

View file

@ -252,6 +252,8 @@ module Psych
e = build_exception((resolve_class($1) || class_loader.exception), e = build_exception((resolve_class($1) || class_loader.exception),
h.delete('message')) h.delete('message'))
e.set_backtrace h.delete('backtrace') if h.key? 'backtrace'
init_with(e, h, o) init_with(e, h, o)
when '!set', 'tag:yaml.org,2002:set' when '!set', 'tag:yaml.org,2002:set'

View file

@ -472,6 +472,9 @@ module Psych
accept msg accept msg
end end
@emitter.scalar 'backtrace', nil, nil, true, false, Nodes::Scalar::ANY
accept o.backtrace
dump_ivars o dump_ivars o
@emitter.end_mapping @emitter.end_mapping

View file

@ -23,6 +23,20 @@ module Psych
$VERBOSE = @orig_verbose $VERBOSE = @orig_verbose
end end
def make_ex msg = 'oh no!'
begin
raise msg
rescue ::Exception => e
e
end
end
def test_backtrace
err = make_ex
new_err = Psych.load(Psych.dump(err))
assert_equal err.backtrace, new_err.backtrace
end
def test_naming_exception def test_naming_exception
err = String.xxx rescue $! err = String.xxx rescue $!
new_err = Psych.load(Psych.dump(err)) new_err = Psych.load(Psych.dump(err))