Skip to content

Commit d48ea99

Browse files
committed
[GR-44053] Do not assume host exception cause has a truffle stack trace.
PullRequest: truffleruby/3661
2 parents f1971ab + 5ef7edd commit d48ea99

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/org/truffleruby/debug/TruffleDebugNodes.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919
import java.util.Map;
2020

21+
import com.oracle.truffle.api.TruffleStackTrace;
2122
import com.oracle.truffle.api.TruffleStackTraceElement;
2223
import com.oracle.truffle.api.exception.AbstractTruffleException;
2324
import com.oracle.truffle.api.frame.Frame;
@@ -489,9 +490,11 @@ public abstract static class ThrowJavaExceptionWithCauseNode extends CoreMethodA
489490
@Specialization(guards = "strings.isRubyString(message)", limit = "1")
490491
protected Object throwJavaExceptionWithCause(Object message,
491492
@Cached RubyStringLibrary strings) {
492-
throw new RuntimeException(
493-
RubyGuards.getJavaString(message),
494-
new RuntimeException("cause 1", new RuntimeException("cause 2")));
493+
var cause2 = new RuntimeException("cause 2");
494+
var cause1 = new RuntimeException("cause 1", cause2);
495+
TruffleStackTrace.fillIn(cause2);
496+
TruffleStackTrace.fillIn(cause1);
497+
throw new RuntimeException(RubyGuards.getJavaString(message), cause1);
495498
}
496499

497500
}

src/main/java/org/truffleruby/language/backtrace/BacktraceFormatter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,10 @@ public static void printInternalError(RubyContext context, Throwable throwable,
421421
printJavaStackTrace(stream, t);
422422

423423
if (TruffleStackTrace.getStackTrace(t) != null) {
424-
stream.println(formatter.formatBacktrace(null, new Backtrace(t)));
424+
var formatted = formatter.formatBacktrace(null, new Backtrace(t));
425+
if (!formatted.isEmpty()) {
426+
stream.println(formatted);
427+
}
425428
}
426429
}
427430
}

0 commit comments

Comments
 (0)