8 ms·
Glad to see "throw on unhandled rejections" make it into Node, finally! I can stop carting around this little bit of code I used in every Node API I wrote: p
by avolcano 6y ago
Glad to see "throw on unhandled rejections" make it into Node, finally! I can stop carting around this little bit of code I used in every Node API I wrote:
process.on('unhandledRejection', (err) => {
console.error(err.stack);
process.exit(1);
});
Had become as second-nature for me as "set -euo pipefail".
- azakai 6y agoVery happy to see this too! In Emscripten we've had to emit a handler like that by default, so that test suites don't silently ignore errors. Being able to not emit it will avoid some code size and annoyances users have had.
- rmrfrmrf 6y agoidk if you've ever run into it, but `process.exit` has been a bit of a footgun in our node apps due to broken pipes and (sometimes) async io with `console` we instead use process.on('unhandledRejection', (reason) => { throw reason; }); which, as long as you havent handled `uncaughtException`, prints the stack trace and aborts.