summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-21 11:44:21 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-21 11:44:21 +0000
commit010a742cb6772d4a27d5fee3606ac9385ca246e0 (patch)
tree164cee8955a2c021286827b5a9475007252dd430
parent09b3d38c724f8e12efe69ea5ee0942335b100764 (diff)
eval_error.c (show_cause): check if cause is an Exception or not
Fixes [Bug #15447] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--eval_error.c2
-rw-r--r--test/ruby/test_exception.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/eval_error.c b/eval_error.c
index 8aab7ba05d0..f9756f65ac0 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 3582cb3de32..88bd095228c 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;