Skip to content

Commit 5f1afc7

Browse files
committed
Rethrow internal errors to the main Ruby Thread
* Currently only AssertionError is not translated by TranslateExceptionNode. (cherry picked from commit d38f28f)
1 parent b57aee2 commit 5f1afc7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/org/truffleruby/core/thread/ThreadManager.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,20 +328,26 @@ private void threadMain(DynamicObject thread, Node currentNode, Supplier<Object>
328328
// Handlers in the same order as in FiberManager
329329
} catch (KillException e) {
330330
setThreadValue(context, thread, Nil.INSTANCE);
331-
} catch (ExitException e) {
332-
rethrowOnMainThread(currentNode, e);
333-
setThreadValue(context, thread, Nil.INSTANCE);
334331
} catch (RaiseException e) {
335332
setException(context, thread, e.getException(), currentNode);
336333
} catch (DynamicReturnException e) {
337334
setException(context, thread, context.getCoreExceptions().unexpectedReturn(currentNode), currentNode);
335+
} catch (ExitException e) {
336+
rethrowOnMainThread(currentNode, e);
337+
setThreadValue(context, thread, Nil.INSTANCE);
338+
} catch (Throwable e) {
339+
final String message = StringUtils
340+
.format("%s terminated with internal error:", Thread.currentThread().getName());
341+
final RuntimeException runtimeException = new RuntimeException(message, e);
342+
rethrowOnMainThread(currentNode, runtimeException);
343+
setThreadValue(context, thread, Nil.INSTANCE);
338344
} finally {
339345
assert Layouts.THREAD.getValue(thread) != null || Layouts.THREAD.getException(thread) != null;
340346
cleanup(thread, Thread.currentThread());
341347
}
342348
}
343349

344-
private void rethrowOnMainThread(Node currentNode, ExitException e) {
350+
private void rethrowOnMainThread(Node currentNode, RuntimeException e) {
345351
context.getSafepointManager().pauseRubyThreadAndExecute(
346352
getRootThread(),
347353
currentNode,

0 commit comments

Comments
 (0)