diff options
-rw-r--r-- | eval_error.c | 2 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/eval_error.c b/eval_error.c index 8aab7ba05d..f9756f65ac 100644 --- a/eval_error.c +++ b/eval_error.c @@ -226,7 +226,7 @@ static void show_cause(VALUE errinfo, VALUE str, VALUE highlight, VALUE reverse) { VALUE cause = rb_attr_get(errinfo, id_cause); - if (!NIL_P(cause)) { + if (!NIL_P(cause) && rb_obj_is_kind_of(cause, rb_eException)) { volatile VALUE eclass = CLASS_OF(cause); VALUE errat = rb_get_backtrace(cause); VALUE emesg = rb_get_message(cause); diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 3582cb3de3..88bd095228 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1341,6 +1341,15 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| assert_in_out_err([], code, [], /Bug14566/, success: false, timeout: 2) end + def test_non_exception_cause + puts "foo" + code = "#{<<~"begin;"}\n#{<<~'end;'}" + begin; + raise "foo", cause: 1 + end; + assert_in_out_err([], code, [], /foo/, success: false, timeout: 2) + end + def test_super_in_method_missing assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; |