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

merge revision(s) 53819,53822: [Backport #12068]

* eval.c (setup_exception): set the cause only if it is explicitly
	  given or not set yet.  [Bug #12068]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@54675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2016-04-22 05:38:08 +00:00
parent 82e65291b1
commit 22a97cbf83
4 changed files with 72 additions and 7 deletions

View file

@ -1,3 +1,8 @@
Fri Apr 22 14:34:27 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (setup_exception): set the cause only if it is explicitly
given or not set yet. [Bug #12068]
Fri Apr 22 14:13:28 2016 sorah (Shota Fukumori) <her@sorah.jp>
* lib/forwardable.rb: Convert given accessors to String.

18
eval.c
View file

@ -24,6 +24,8 @@ NORETURN(void rb_raise_jump(VALUE, VALUE));
VALUE rb_eLocalJumpError;
VALUE rb_eSysStackError;
static ID id_cause;
#define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
#include "eval_error.c"
@ -450,9 +452,6 @@ static VALUE get_thread_errinfo(rb_thread_t *th);
static VALUE
exc_setup_cause(VALUE exc, VALUE cause)
{
ID id_cause;
CONST_ID(id_cause, "cause");
#if SUPPORT_JOKE
if (NIL_P(cause)) {
ID id_true_cause;
@ -496,10 +495,15 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
nocause = 0;
}
if (cause == Qundef) {
cause = nocause ? Qnil : get_thread_errinfo(th);
if (cause != Qundef) {
exc_setup_cause(mesg, cause);
}
else if (nocause) {
exc_setup_cause(mesg, Qnil);
}
else if (!rb_ivar_defined(mesg, id_cause)) {
exc_setup_cause(mesg, get_thread_errinfo(th));
}
exc_setup_cause(mesg, cause);
file = rb_sourcefile();
if (file) line = rb_sourceline();
@ -1710,4 +1714,6 @@ Init_eval(void)
rb_define_global_function("untrace_var", rb_f_untrace_var, -1); /* in variable.c */
rb_vm_register_special_exception(ruby_error_reenter, rb_eFatal, "exception reentered");
id_cause = rb_intern_const("cause");
}

View file

@ -618,6 +618,41 @@ end.join
assert_not_same(e, e.cause, "#{msg}: should not be recursive")
end
def test_cause_raised_in_rescue
e = assert_raise_with_message(RuntimeError, 'b') {
begin
raise 'a'
rescue => a
begin
raise 'b'
rescue => b
begin
raise 'c'
rescue
raise b
end
end
end
}
assert_equal('a', e.cause.message, 'cause should not be overwritten by reraise')
end
def test_cause_at_raised
e = assert_raise_with_message(RuntimeError, 'b') {
begin
raise 'a'
rescue => a
b = RuntimeError.new('b')
begin
raise 'c'
rescue
raise b
end
end
}
assert_equal('c', e.cause.message, 'cause should be the exception at raised')
end
def test_raise_with_cause
msg = "[Feature #8257]"
cause = ArgumentError.new("foobar")
@ -632,6 +667,25 @@ end.join
end
end
def test_raise_with_cause_in_rescue
e = assert_raise_with_message(RuntimeError, 'b') {
begin
raise 'a'
rescue => a
begin
raise 'b'
rescue => b
begin
raise 'c'
rescue
raise b, cause: ArgumentError.new('d')
end
end
end
}
assert_equal('d', e.cause.message, 'cause option should be honored always')
end
def test_unknown_option
bug = '[ruby-core:63203] [Feature #8257] should pass unknown options'

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.5"
#define RUBY_RELEASE_DATE "2016-04-22"
#define RUBY_PATCHLEVEL 296
#define RUBY_PATCHLEVEL 297
#define RUBY_RELEASE_YEAR 2016
#define RUBY_RELEASE_MONTH 4