floatdrop / gulp-plumber

Fixing Node pipes
MIT License
806 stars 32 forks source link

Plumber failing to continue after async error #34

Open rimassa opened 9 years ago

rimassa commented 9 years ago

Hello!

I wrote three simplified scenarios to try to understand why plumber is failing to keep the stream flow after some error ocurred on my plugin (which transforms vinyl files asynchronously).

I'm using node v0.12.2 and I'm running my tests with node gulp.js

This is the first case: https://gist.github.com/rimassa/229af1fe328bff31e817 It's a simple pipeline, which retrieves files from a instance of FileSource, passes them through a plugin (which just re-emitts the same files after 100 milliseconds and stores them in a instance of FileDest. Plumber is connected right after the FileSource. My plugins does not emit any errors and everything works perfectly, as you can see on "output.log".

This is the second scenario: https://gist.github.com/rimassa/62ce1f9d2573096d549a This code is almost identical to the previous one, except for my plugin. It emits an error on the fifth file, by calling cb(new Error(...)). As you may notice on the file 'output.log', plumber is not able to recover the stream flow: the processing stops at the fifth file.

I was able to make this work in the third case: https://gist.github.com/rimassa/dfa57285d3898c9fe0c6 I've just replaced cb(new Error(...)) with this.emit('error', new Error(...)); cb(). Now plumber seems to handle the error and resume the stream, processing the next five files.

Why does it happens? Is it ok to use the workaround I did on the last scenario?

Cheers Ricardo

floatdrop commented 9 years ago

Wild guess - in second example gulp-plumber actually catches error, but still Transform stream is considered itself broken so no more further piping happening. You can dig inside Transform and stream module to figure it out. (sorry, I have little free time atm, feel free to ask questions thou :dog:)