-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
uncaughtException origin is always unhandledRejection when package.json type is module #41328
Comments
I suppose Lines 336 to 340 in 86099a3
mkdir repro
cd repro
echo 'process.on("uncaughtException", (_, origin) => console.log(origin));unknownFunction()' > test.mjs
node --unhandled-rejections=none test.mjs # logs unhandleRejection, despite what the docs claim @nodejs/modules is there a way to differentiate errors throw synchronously from unhandled rejections in an ES module? Or should we simply update the docs to document the current behavior? |
I see this behavior as sadly expected/unavoidable but confusing like many ESM expectations broken from transpiled forms; we should update the docs. In certain cases we can detect if the error was thrown during evaluation but in general even with that, all handling is done through Promise style handling. E.G. let nsPromise = import('a');
|
Yes, the file extension is Hopefully, it can be fixed for at least some cases. |
To be clear, I'm skeptical that we should change it without more understanding of the actual ask here. Right now the behavior of // note that this is synchronously executed:
new Promise(f => require('./file-that-throws.cjs')) What is the exact thing we are trying to achieve rather than jumping to try and change behaviors? I see something about:
Right now ESM never ever emits |
It was discussed in the linked PR, but I think it's worth pointing it out here: the title of this issue is not quite true, you can still get process.on('uncaughtException', (_, origin) => {
console.log('whoops, uncaughtException', origin)
})
setImmediate(() => unknownFunction()) |
I think the whole goal of the unhandled rejection changes last year was for the behaviour of uncaughtException and unhandledRejection to be similar. It is very easy today to make an |
Fixes: #41328 PR-URL: #41339 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Bradley Farias <[email protected]>
Fixes: #41328 PR-URL: #41339 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Bradley Farias <[email protected]>
Fixes: nodejs#41328 PR-URL: nodejs#41339 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Bradley Farias <[email protected]>
Fixes: nodejs#41328 PR-URL: nodejs#41339 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Bradley Farias <[email protected]>
Fixes: #41328 PR-URL: #41339 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Bradley Farias <[email protected]>
Version
v16.13.1
Platform
mac os 10.14.6, Darwin uladzislaus-mbp 18.7.0 Darwin Kernel Version 18.7.0: Sun Dec 1 18:59:03 PST 2019; root:xnu-4903.278.19~1/RELEASE_X86_64 x86_64
Subsystem
No response
What steps will reproduce the bug?
node <name-of-the-file>
whoops, uncaughtException uncaughtException
package.json
file next to script file with contents:node <name-of-the-file>
whoops, uncaughtException unhandledRejection
How often does it reproduce? Is there a required condition?
In package.json file,
type
should bemodule
to see the bug.What is the expected behavior?
uncaughtException
origin should beuncaughtException
What do you see instead?
uncaughtException
origin isunhandledRejection
Additional information
No response
The text was updated successfully, but these errors were encountered: