News for hackers. Stuff that matters.
Re:After a year of using Node.js in production by pjungwir on Monday May 02, 2016 @05:47PM (#11615953)
I gave a talk about handling errors in Node a few years ago:

https://github.com/pjungwir/node-errors-talk

At the time the solution was "use domains", but I think domains are deprecated now. It was painful enough that I have stuck with Rails since then. I'm glad to hear that Promises are an improvement!

Re:After a year of using Node.js in production by koolba on Monday May 02, 2016 @06:36PM (#11616305)
Domains have been deprecated since at least 0.10. As of yet there's no replacement for them and all node apps should be using them. There's no other way to catch "But ... but ... that can't happen!" type errors.
Re:After a year of using Node.js in production by spion on Monday May 02, 2016 @06:58PM (#11616425)
There is no replacement because they're a fundamentally broken idea. They require the following to happen, in that order:

* V8 needs to optimize try-finally

* Node core needs to add try-finally at every single place where callbacks are invoked and make sure all state and resource cleanup is properly done to support domains

* Popular libraries need to also add try-finally handlers for the above.

As to why this is a problem in node and not so much in other languages, its because with node callbacks, the call stack goes both ways. In other languages, libraries mostly call their dependencies' code. In node's CPS style, you call the library but the library also calls your closure code. The semantics for the 2nd part aren't well defined in node - the loose law basically says: I wont call you twice, I'll try not to call you synchronously, and you wont throw (and if you do the behavior is undefined).

With promises there is a contract and its enforced by the promise implementation. Since Promises actually have error semantics, you can build resource management strategies on top of them. http://promise-nuggets.github.io/articles/21-context-manager... - and consequently there is no reason to crash your server on errors.

Re:After a year of using Node.js in production by lobster_johnson on Monday May 02, 2016 @11:27PM (#11617672)
Domains are used for another reason: To emulate thread-local variables. I hope that support is not going away, because it's really handy.
Re:After a year of using Node.js in production by spion on Friday May 06, 2016 @11:29AM (#11644613)
Its interesting that the same problem (TLS) can also be solved with something similar to promises :)
Re:After a year of using Node.js in production by 0xmohit on Monday May 02, 2016 @09:18PM (#11617141)
"A few years" is a very long time for a relatively new and evolving language.

Perhaps that is the reason that people have become more conscious of making _drastic_ changes -- rust and go are examples.