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

Refactor exception dumping

This commit is contained in:
Aaron Patterson 2019-01-09 13:28:08 -08:00 committed by Hiroshi SHIBATA
parent 4bd1909427
commit f770a5be66

View file

@ -181,37 +181,11 @@ module Psych
end
def visit_Exception o
tag = ['!ruby/exception', o.class.name].join ':'
@emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
msg = private_iv_get(o, 'mesg')
if msg
@emitter.scalar 'message', nil, nil, true, false, Nodes::Scalar::ANY
accept msg
end
dump_ivars o
@emitter.end_mapping
dump_exception o, private_iv_get(o, 'mesg')
end
def visit_NameError o
tag = ['!ruby/exception', o.class.name].join ':'
@emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
msg = o.message.to_s
if msg
@emitter.scalar 'message', nil, nil, true, false, Nodes::Scalar::ANY
accept msg
end
dump_ivars o
@emitter.end_mapping
dump_exception o, o.message.to_s
end
def visit_Regexp o
@ -488,6 +462,21 @@ module Psych
def dump_list o
end
def dump_exception o, msg
tag = ['!ruby/exception', o.class.name].join ':'
@emitter.start_mapping nil, tag, false, Nodes::Mapping::BLOCK
if msg
@emitter.scalar 'message', nil, nil, true, false, Nodes::Scalar::ANY
accept msg
end
dump_ivars o
@emitter.end_mapping
end
def format_time time
if time.utc?
time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")