Open AsyncProxy opened 4 months ago
Errors in APIs such as setTimeout and setnterval cannot be caught, and errors will be thrown directly.
Error
setTimeout(() => {throw new Error('')}) ^ Error at Timeout._onTimeout (c.js:5:25) at listOnTimeout (node:internal/timers:573:17) at process.processTimers (node:internal/timers:514:7) --------- beginning of crash 2024-05-30 19:58:41.669 3792-3828 nodejs com.proxy.plus E Node.js v20.12.2 ```js
Any API with blocking, Java can't stop the engine from reporting errors.
This is a Node.js feature that you missed. Basically, application is supposed to listen the event uncaughtException
, otherwise, Node.js crashes.
Please review the following test code.
nodeRuntime.getExecutor("let a = [];\n" +
"process.on('uncaughtException', (error, origin) => {\n" +
" a.push(origin, error);\n" +
"});").executeVoid();
nodeRuntime.getExecutor("setTimeout(() => { throw new Error('Error'); }, 0);").executeVoid();
nodeRuntime.await();
assertEquals("uncaughtException", nodeRuntime.getExecutor("a[0]").executeString());
try (V8ValueError v8ValueError = nodeRuntime.getExecutor("a[1]").execute()) {
assertEquals("Error", v8ValueError.getMessage());
}
uncaughtException
Sorry so much, this is my problem, I'm using unhandledRejection instead of uncaughtException, much appreciated!
This is a Node.js feature that you missed. Basically, application is supposed to listen the event , otherwise, Node.js crashes.
uncaughtException
Please review the following test code.
nodeRuntime.getExecutor("let a = [];\n" + "process.on('uncaughtException', (error, origin) => {\n" + " a.push(origin, error);\n" + "});").executeVoid(); nodeRuntime.getExecutor("setTimeout(() => { throw new Error('Error'); }, 0);").executeVoid(); nodeRuntime.await(); assertEquals("uncaughtException", nodeRuntime.getExecutor("a[0]").executeString()); try (V8ValueError v8ValueError = nodeRuntime.getExecutor("a[1]").execute()) { assertEquals("Error", v8ValueError.getMessage()); }
And I replied that the reason why 3.1.2 can't start is because of setResourceName, if the Node.js engine uses this api, the engine won't execute.
@caoccao Is it possible to make the exception catchable in Java? So the program can to things correspondingly like close resources, cancel jobs etc. And perhaps just to prevent it crash the system entirely.
For example in this scenario:
nodeRuntime.getExecutor(script).setModule(true).executeVoid()
I figured it is setModule(true)
that causes the problem.
Errors in APIs such as setTimeout and setnterval cannot be caught, and errors will be thrown directly.
Error