News for hackers. Stuff that matters.
Re:Node v6.9.0 (LTS) by _greim_ on Tuesday October 18, 2016 @06:59PM (#12739500)
> it is quite literally silently swallowing ALL exceptions thrown

Technically, it propagates the error along to any dependent promises. If nobody's handling errors, then yes, they get swallowed. If that bugs you, all you have to do is add this once when your app starts up:

    process.on('unhandledRejection', function(ex) {
      console.error(ex.stack);
      process.exit(1);
    });
I think that should have been the default, personally, but it's a nuisance at worst. Throwing out promises because of this is absurd thinking.
Re:Node v6.9.0 (LTS) by james-mcelwain on Tuesday October 18, 2016 @08:08PM (#12739848)
Killing a process on an exception you can't handle is sort of best practice anyway in Node--assuming you're not building important financial services or whatever in Node (lol).

Like, you want to be careful not to open yourself up to cascading failure, but if my application has a random exception, the 100ms start up time of the JavaScript VM means its almost always worth the cost of restarting to ensure your application isn't in an unstable state.

Re:Node v6.9.0 (LTS) by danneu on Tuesday October 18, 2016 @09:00PM (#12740107)
I'd rethink that. Every connection to the server closes, and whatever else it might be doing stops, because someone hits your syntax error? And they completely DoS your server by slowly refreshing the page?

Surely the best practice is to use something like koa or otherwise create a promise chain with a top-level 500 handler.

Re:Node v6.9.0 (LTS) by mnutt on Tuesday October 18, 2016 @10:09PM (#12740452)
Depending on how much state your applications carry forward, I think killing the process is often the right thing to do. Otherwise, it's very easy to end up with connection leaks or just downright confusing state that can't always easily be traced back to what should have been an exception.

I run a node app that serves ~500M requests a day that is configured to die on exceptions, it just means that we do everything we can to prevent them (unit tests, linters, etc) and take them very seriously when they happen.

Re:Node v6.9.0 (LTS) by Touche on Tuesday October 18, 2016 @08:51PM (#12740070)
What makes you think I can't handle it? I definitely can handle it, and Promises give me the ability to handle them.
Re:Node v6.9.0 (LTS) by nilliams on Wednesday October 19, 2016 @04:05AM (#12741965)
In my example I was talking about avoiding es6-promise polyfill in the browser, because of the fact that it adheres so strictly to the spec that it does not have an equivalent to the safety net you give in your Node example.
Re:Node v6.9.0 (LTS) by _greim_ on Friday October 21, 2016 @12:14AM (#12758109)
Yeah polyfills might not do the right thing. Natively, both exceptions and rejections stop the next thing from happening, give you a trace in the console, then everything continues at the next tick of the event loop. If a polyfill skips the trace part, that's definitely bad.
Re:Node v6.9.0 (LTS) by nilliams on Friday October 21, 2016 @03:48PM (#12763994)
Yep I know, I'm specifically complaining about the current trend of casting off old ajax methods/libraries and moving to 'fetch()' polyfills, as currently the 2 main popular fetch modules both recommend 'es6-promise' as polyfill which has serious problems in this regard: https://github.com/matthew-andrews/isomorphic-fetch/issues/1...

Technically however, what that polyfill is doing is 'on-spec'. Note that your `process.on('unhandledRejection')` thing is clearly outside spec as `process` is a Node thing, not a JS thing.