Hacker News new | past | comments | ask | show | jobs | submit login

Giant post about the nightmare that is making robust code in node.js. Summary, don't use a language in large projects that makes it so easy to leak errors and exceptions. There's something to be said about the compiler forcing you to declare what exceptions your code can throw to force you to think about this stuff up front.



Not really, just normal error handling issues like most other languages.

You should always know how the api you are using returns an error and use it - most langauges have multiple common ways of notifying of an error.

As to leaking, coming from Java's terrible error handling, you just start using runtime errors all the time anyway, at least with js the result is more concise.


Node is actually best used with Promises, which aren't even mentioned in this post.

Promises, aside from being far more concise with a huge amount of utility, do not leak errors or exceptions.

    doAMillionThings()
    .catch((err) => handleAnything(err));


What better alternatives do you know? I don't know any programming language for real world projects that would make error handling trivial.


Trivial? No. But you can at least make it better than the horrible nightmare described in the OP. Monadic error handling in a strongly typed language gives you a huge leg up on safely and sanely managing the complexity of error handling, because it provides simple value-level error semantics and clear type-level indications of exactly what kinds of errors you have to deal with and how you have to deal with them.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: