Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engine error #345

Open
AsyncProxy opened this issue May 30, 2024 · 5 comments
Open

Engine error #345

AsyncProxy opened this issue May 30, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@AsyncProxy
Copy link

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
@AsyncProxy
Copy link
Author

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.

@caoccao
Copy link
Owner

caoccao commented May 31, 2024

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());
}

@caoccao caoccao added the help wanted Extra attention is needed label May 31, 2024
@AsyncProxy
Copy link
Author

uncaughtException

Sorry so much, this is my problem, I'm using unhandledRejection instead of uncaughtException, much appreciated!

@AsyncProxy
Copy link
Author

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.

@TapiocaFox
Copy link

TapiocaFox commented Sep 10, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants