Skip to content

Commit

Permalink
Rethrow the existing TruffleException if there is one in #raise to pr…
Browse files Browse the repository at this point in the history
…eserve the backtrace

* Fixes #1459.
  • Loading branch information
eregon committed Nov 15, 2018
1 parent 0e1f24a commit f780b49
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bug fixes:
* `ArgumentError` messages now better match MRI (#1467).
* Added support for `:float_millisecond`, `:millisecond`, and
`:second` time units to `Process.clock_gettime` (#1468).
* Fixed backtrace of re-raised exceptions (#1459).

Changes:

Expand Down
1 change: 0 additions & 1 deletion spec/tags/core/kernel/raise_tags.txt

This file was deleted.

13 changes: 11 additions & 2 deletions src/main/java/org/truffleruby/core/VMPrimitiveNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.truffleruby.core.rope.CodeRange;
import org.truffleruby.core.string.StringNodes;
import org.truffleruby.core.string.StringOperations;
import org.truffleruby.language.backtrace.Backtrace;
import org.truffleruby.language.control.ExitException;
import org.truffleruby.language.control.RaiseException;
import org.truffleruby.language.control.ThrowException;
Expand Down Expand Up @@ -214,8 +215,16 @@ public Object vmObjectClass(Object object) {
public static abstract class VMRaiseExceptionPrimitiveNode extends PrimitiveArrayArgumentsNode {

@Specialization(guards = "isRubyException(exception)")
public DynamicObject vmRaiseException(DynamicObject exception, boolean internal) {
throw new RaiseException(getContext(), exception, internal);
public DynamicObject vmRaiseException(DynamicObject exception, boolean internal,
@Cached("createBinaryProfile()") ConditionProfile reRaiseProfile) {
final Backtrace backtrace = Layouts.EXCEPTION.getBacktrace(exception);
if (reRaiseProfile.profile(backtrace != null && backtrace.getTruffleException() != null)) {
// We need to rethrow the existing TruffleException, otherwise we would lose the
// incremental backtrace accumulated in it.
throw (RaiseException) backtrace.getTruffleException();
} else {
throw new RaiseException(getContext(), exception, internal);
}
}

}
Expand Down

0 comments on commit f780b49

Please sign in to comment.