Hacker News new | ask | show | jobs
by avolcano 2058 days 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".
2 comments

idk 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.
Very 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.