Error handling with node.js streams

What’s the correct way to handle errors with streams? I already know there’s an ‘error’ event you can listen on, but I want to know some more details about arbitrarily complicated situations.

For starters, what do you do when you want to do a simple pipe chain:

input.pipe(transformA).pipe(transformB).pipe(transformC)...

And how do you properly create one of those transforms so that errors are handled correctly?

More related questions:

  • when an error happens, what happens to the ‘end’ event? Does it never get fired? Does it sometimes get fired? Does it depend on the transform/stream? What are the standards here?
  • are there any mechanisms for propogating errors through the pipes?
  • do domains solve this problem effectively? Examples would be nice.
  • do errors that come out of ‘error’ events have stack traces? Sometimes? Never? is there a way to get one from them?

9 Answers
9

Leave a Comment