Skip to content

Commit 0751e3b

Browse files
committed
Include Java exception stack traces in wrapped Java exceptions if WithJavaStacktrace is set
1 parent a7472a5 commit 0751e3b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/ErrorMessageFormatter.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@
4040
*/
4141
package com.oracle.graal.python.runtime.formatting;
4242

43+
import java.io.PrintWriter;
44+
import java.io.StringWriter;
4345
import java.util.Formatter;
4446
import java.util.regex.Matcher;
4547
import java.util.regex.Pattern;
4648

49+
import com.oracle.graal.python.PythonLanguage;
4750
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
4851
import com.oracle.graal.python.nodes.object.GetClassNode;
52+
import com.oracle.graal.python.runtime.PythonOptions;
4953
import com.oracle.graal.python.util.PythonUtils;
5054
import com.oracle.truffle.api.CompilerAsserts;
5155
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -128,7 +132,15 @@ public String format(String format, Object... args) {
128132

129133
@TruffleBoundary
130134
private static String getMessage(Throwable exception) {
131-
return exception.getClass().getSimpleName() + ": " + exception.getMessage();
135+
String message = exception.getClass().getSimpleName() + ": " + exception.getMessage();
136+
if (PythonOptions.isWithJavaStacktrace(PythonLanguage.get(null))) {
137+
StringWriter writer = new StringWriter();
138+
try (PrintWriter pw = new PrintWriter(writer)) {
139+
exception.printStackTrace(pw);
140+
}
141+
message += "\n\nJava stack trace:\n" + writer;
142+
}
143+
return message;
132144
}
133145

134146
private static String getClassName(Object obj) {

0 commit comments

Comments
 (0)