Skip to content

Commit 6e13509

Browse files
committed
Re-raising an exception no longer sets the cause.
1 parent 79898d8 commit 6e13509

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Bug fixes:
55
* Fixed `BigDecimal#dup` so it now just returns the receiver, per Ruby 2.5+ semantics (#1680).
66
* Implemented `rb_eval_string_protect`.
77
* Fixed `rb_get_kwargs` to correctly handle optional and rest arguments.
8+
* Calling `Kernel#raise` with a raised exception will no longer set the cause of the exception to itself (#1682).
89

910
# 1.0 RC 17
1011

spec/ruby/core/exception/cause_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@
4141
e.cause.should equal(cause)
4242
}
4343
end
44+
45+
it "is not set to the exception itself when it is re-raised" do
46+
-> {
47+
begin
48+
raise RuntimeError
49+
rescue RuntimeError => e
50+
raise e
51+
end
52+
}.should raise_error(RuntimeError) { |e|
53+
e.cause.should == nil
54+
}
55+
end
4456
end

src/main/ruby/core/truffle/kernel_operations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def self.internal_raise(exc, msg, ctx, internal)
141141
unless skip
142142
exc.set_context ctx if ctx
143143
exc.capture_backtrace!(2) unless exc.backtrace?
144-
Truffle.invoke_primitive :exception_set_cause, exc, $!
144+
Truffle.invoke_primitive :exception_set_cause, exc, $! unless exc.equal?($!)
145145
end
146146

147147
if $DEBUG

0 commit comments

Comments
 (0)