dominictarr / split

MIT License
347 stars 39 forks source link

Doesn't propagate errors #20

Closed atombender closed 9 years ago

atombender commented 9 years ago

If you do this, then no errors from the piped stream will be caught:

let lines = stream.pipe(split(/\r?\n/));
lines.on('error', err => ...);

One has to listen to error events on the original stream:

stream.on('error', err => ...);
let lines = stream.pipe(split(/\r?\n/));

To let errors propagate correctly (for example, when using Rx/RxNode), one can do this:

let lines = stream.pipe(split(/\r?\n/));
stream.on('error', err => {
  lines.emit('error', err);
});
lines.on('error', err => ...);  // Now works correctly

I suspect that split should propagate errors this way.

dominictarr commented 9 years ago

yes, unfortunately node streams just do not work like this (split is just an easier interface to the classic node streams)

however, if you do need error propagation, with regular node streams, you can use this module: https://github.com/mafintosh/pump

atombender commented 9 years ago

Understood. Thanks!