Restrict cause to an exception object [Bug #15447]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9777547817
commit
c20a1946a6
3
eval.c
3
eval.c
@ -509,6 +509,9 @@ exc_setup_message(const rb_execution_context_t *ec, VALUE mesg, VALUE *cause)
|
|||||||
*cause = get_ec_errinfo(ec);
|
*cause = get_ec_errinfo(ec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!NIL_P(*cause) && !rb_obj_is_kind_of(*cause, rb_eException)) {
|
||||||
|
rb_raise(rb_eTypeError, "exception object expected");
|
||||||
|
}
|
||||||
return mesg;
|
return mesg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -808,7 +808,7 @@ end.join
|
|||||||
e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar"}
|
e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar"}
|
||||||
assert_equal({"foo" => "bar", foo: "bar"}, e.arg, bug)
|
assert_equal({"foo" => "bar", foo: "bar"}, e.arg, bug)
|
||||||
|
|
||||||
e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar", cause: "zzz"}
|
e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar", cause: RuntimeError.new("zzz")}
|
||||||
assert_equal({"foo" => "bar", foo: "bar"}, e.arg, bug)
|
assert_equal({"foo" => "bar", foo: "bar"}, e.arg, bug)
|
||||||
|
|
||||||
e = assert_raise(exc, bug) {raise exc, {}}
|
e = assert_raise(exc, bug) {raise exc, {}}
|
||||||
@ -1346,11 +1346,9 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_non_exception_cause
|
def test_non_exception_cause
|
||||||
code = "#{<<~"begin;"}\n#{<<~'end;'}"
|
assert_raise_with_message(TypeError, /exception/) do
|
||||||
begin;
|
|
||||||
raise "foo", cause: 1
|
raise "foo", cause: 1
|
||||||
end;
|
end;
|
||||||
assert_in_out_err([], code, [], /foo/, success: false, timeout: 2)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_circular_cause_handle
|
def test_circular_cause_handle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user