deno: unhandledrejection is not working for anonymous async function promises. Some code works in nodejs
Deno (1.18.3)
import {delay} from "std/async/delay.ts";
globalThis.addEventListener("unhandledrejection", (error) => {
console.error('unhandledRejection', error);
e.preventDefault();
});
(async () => {
throw 'failed';
})();
await delay(5_000);
console.log('success');
Node (19.1.0)
process.on('unhandledRejection', (error) => {
console.error('unhandledRejection', error);
});
(async () => {
throw 'failed';
})();
await new Promise((resolve) => setTimeout(resolve, 5_000));
console.log('success');
Result: error: Uncaught “failed”
Expected: success
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (13 by maintainers)
I was suggesting a private API like:
Deno[Deno.internal].node.unhandledRejectionHandler
How about adding a special API to get listener count of EventTarget?
And use it like:
After some debugging and discussion with @dsherret I pinpointed that this is caused by
npm:
imports, which suggests that it’s related to Node compatibility layer. I will debug it further, as it’s possibly related to https://github.com/denoland/deno/issues/16628