Earlier quoted context omitted.
One of the things I love about node.js is that it forces you to come up with a style and stick with it for things like this. At http://ratchet.io our API servers are written in node.js and we chose the foo(err, callback) method. I personally love this style even though it makes you write more boiler-plate code, it forces you to write exception-safe code from the start. Also, it forces a structure on all of your code…
How do you deal with code where the author forgot to handle all of the failure cases and invoke the callback?
Node.js error handling
21–24 of 24 posts
Re: Node.js error handling
#22I actually just wrote a Node + Express + Backbone error handling system today. I've been staying sane through the use of the 'Q' promise package ( https://github.com/kriskowal/q ). For example, in the below code chunk any errors thrown in makeEmailConfirmation or sendEmailConfirmation will land in the .fail() catch block. I believe using a promise system is the only way to avoid callback hell. var deferred = Q.defer(…
Re: Node.js error handling
#23So the recommendation is to restart the process - but let's not forget that hundreds+ of other requests could currently be in the pipeline - are we just going to abort those too?
Ok, we'll clearly the solution is to wrap all our callbacks with try/catch! Shoot me now...
For large, sprawling applications used to support a business, something like https://github.com/scriby/asyncblock can resolve most of the headaches with async code, including error handling. It's worked out well for my team at work, which is building a "very large" node application.
Disclaimer: Asyncblock is my pet project.
Re: Node.js error handling
#24I actually just wrote a Node + Express + Backbone error handling system today. I've been staying sane through the use of the 'Q' promise package ( https://github.com/kriskowal/q ). For example, in the below code chunk any errors thrown in makeEmailConfirmation or sendEmailConfirmation will land in the .fail() catch block. I believe using a promise system is the only way to avoid callback hell. var deferred = Q.defer(…