Skip to content

Commit c2f26ac

Browse files
committed
TopLevelExceptionHandler: if exception is AssertionError and no java stack trace: print info helper message to use WithJavaStackTrace
1 parent 4a9bfa8 commit c2f26ac

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.RecursionError;
4444
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_WRITE;
4545
import static com.oracle.graal.python.nodes.BuiltinNames.T_SYS;
46+
import static com.oracle.graal.python.runtime.exception.ExceptionUtils.printToStdErr;
4647
import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemExit;
4748
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
4849

@@ -219,7 +220,11 @@ private void handleJavaException(Throwable e) {
219220
boolean exitException = InteropLibrary.getUncached().isException(e) && InteropLibrary.getUncached().getExceptionType(e) == ExceptionType.EXIT;
220221
if (!exitException) {
221222
ExceptionUtils.printPythonLikeStackTrace(getContext(), e);
222-
if (PythonOptions.isWithJavaStacktrace(getPythonLanguage())) {
223+
boolean withJavaStacktrace = PythonOptions.isWithJavaStacktrace(getPythonLanguage());
224+
if (e instanceof AssertionError && !withJavaStacktrace) {
225+
printToStdErr("To get more information about the failed assertion rerun with --python.WithJavaStacktrace=3\n");
226+
}
227+
if (withJavaStacktrace) {
223228
e.printStackTrace();
224229
}
225230
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ private static int getLineno(Frame frame) {
113113
return lineno;
114114
}
115115

116+
@TruffleBoundary
117+
public static void printToStdErr(String message, Object... args) {
118+
PrintWriter printWriter = new PrintWriter(System.err, true);
119+
printWriter.printf(message, args);
120+
}
121+
116122
/**
117123
* this method is similar to 'PyErr_WriteUnraisable' and may be used when the context is not
118124
* available.
@@ -151,7 +157,8 @@ public static void printPythonLikeStackTrace(PrintWriter p, Throwable e) {
151157
throw CompilerDirectives.shouldNotReachHere();
152158
}
153159
} else {
154-
p.println(e.getMessage());
160+
String message = e.getMessage();
161+
p.println(message == null ? e.getClass().getSimpleName() : message);
155162
}
156163
}
157164

0 commit comments

Comments
 (0)