8000 [GR-61865] Backport to 24.2: Rethrow internal errors during PythonLan… · oracle/graalpython@6b8238e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b8238e

Browse files
committed
[GR-61865] Backport to 24.2: Rethrow internal errors during PythonLanguage#initializeContext.
PullRequest: graalpython/3683
2 parents 0682cf1 + 7c829c5 commit 6b8238e

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ protected void launch(Builder contextBuilder) {
843843
} catch (PolyglotException e) {
844844
if (e.isExit()) {
845845
rc = e.getExitStatus();
846+
} else {
847+
throw e;
846848
}
847849
} catch (NoSuchFileException e) {
848850
printFileNotFoundException(e);

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,7 @@ private AbstractTruffleException handlePythonException(AbstractTruffleException
195195
if (PythonOptions.isPExceptionWithJavaStacktrace(getPythonLanguage()) && e instanceof PException pe) {
196196
ExceptionUtils.printJavaStackTrace(pe);
197197
}
198-
if (!getSourceSection().getSource().isInteractive()) {
199-
if (getContext().isChildContext()) {
200-
getContext().getChildContextData().setExitCode(1);
201-
}
202-
throw new PythonExitException(this, 1);
203-
}
198+
exit(1);
204199
}
205200
// Before we leave Python, format the message since outside the context
206201
if (e instanceof PException pe) {
@@ -209,6 +204,15 @@ private AbstractTruffleException handlePythonException(AbstractTruffleException
209204
throw e;
210205
}
211206

207+
private void exit(int exitCode) {
208+
if (!getSourceSection().getSource().isInteractive()) {
209+
if (getContext().isChildContext()) {
210+
getContext().getChildContextData().setExitCode(1);
211+
}
212+
throw new PythonExitException(this, exitCode);
213+
}
214+
}
215+
212216
private static boolean isSystemExit(PBaseException pythonException) {
213217
return IsBuiltinClassProfile.profileClassSlowPath(GetPythonObjectClassNode.executeUncached(pythonException), SystemExit);
214218
}
@@ -227,6 +231,7 @@ private void handleJavaException(Throwable e) {
227231
if (PythonOptions.shouldPrintJavaStacktrace(getPythonLanguage(), e)) {
228232
e.printStackTrace();
229233
}
234+
exit(1);
230235
}
231236
} catch (UnsupportedMessageException unsupportedMessageException) {
232237
throw CompilerDirectives.shouldNotReachHere();
@@ -250,12 +255,12 @@ private void handleSystemExit(PBaseException pythonException) {
250255
int exitcode = getExitCode(pythonException);
251256
throw new PythonExitException(this, exitcode);
252257
} catch (CannotCastException e) {
253-
// fall through
254-
}
255-
if (handleAlwaysRunExceptHook(theContext, pythonException)) {
256-
throw new PythonExitException(this, 1);
258+
if (handleAlwaysRunExceptHook(theContext, pythonException)) {
259+
throw new PythonExitException(this, 1);
260+
} else {
261+
throw pythonException.getExceptionForReraise(pythonException.getTraceback());
262+
}
257263
}
258-
throw pythonException.getExceptionForReraise(pythonException.getTraceback());
259264
}
260265

261266
@TruffleBoundary
@@ -264,12 +269,12 @@ private Object handleChildContextExit(PBaseException pythonException) throws PEx
264269
try {
265270
return getExitCode(pythonException);
266271
} catch (CannotCastException cce) {
267-
// fall through
268-
}
269-
if (handleAlwaysRunExceptHook(getContext(), pythonException)) {
270-
return 1;
272+
if (handleAlwaysRunExceptHook(getContext(), pythonException)) {
273+
return 1;
274+
} else {
275+
throw pythonException.getExceptionForReraise(pythonException.getTraceback());
276+
}
271277
}
272-
throw pythonException.getExceptionForReraise(pythonException.getTraceback());
273278
}
274279

275280
private static int getExitCode(PBaseException pythonException) throws CannotCastException {

0 commit comments

Comments
 (0)
0