Sucking at something is the first step to becoming sorta good at something

No one can assure you, that plugins will run smooth in any circumstances (except for tests - they could), so neither should you convince anyone, that your plugin will never break. Only thing, that you could possibly do (if something gone wrong) - is gracefully inform your plugin user, that something went wrong and die.

We are will use this plugin from beginning to demonstrate error management. Suppose you have a task in gulpfile.js that contains this code (we modified it a little bit to be closer to real-usage):

What could possibly go wrong? Well gulpPrefixer could emit errors event, as any of Stream gulp-plugins, for example gulp-sass. If you don't do anything with it inside task, Node will throw errors and whole task will be stopped.

You can easily avoid it by catch them and show by appending .on('error', gutil.log) handlers:

But this will not solve "stopping" problem of the task. By design, Node stream will stop accepting incoming data, if error event was raised. You can see it in stream.js:103 - cleanup function will deattach ondata handler from source (which in our case is gulp.src) and coffee plugin will stop receiving files although, the rest of the files can be compiled.

For now, we have no other solution besides patching pipe function behaviour. So the gulp-plumber may fix this problem:

This comment has been minimized.

Hi guys,
Did someone here manage to have gulp work nicely with stylus ? I have set a small watch task with a pipe through stylus, autoprefixer and others, and it crashes altogether if stylus encounters a problem on compiling (like a bad indent).

Hi guys,
Did someone here manage to have gulp work nicely with stylus ? I have set a small watch task with a pipe through stylus, autoprefixer and others, and it crashes altogether if stylus encounters a problem on compiling (like a bad indent).

This comment has been minimized.

@FieryCod This is mid of 2017 and yes plumber is a go-away-error kind of tool. Many plugins, particularly gulp-sass throw@import error because file is not ready or unreadable. Whenever sass compiler complies SASS files, dont know how, but it takes more time in pipe and next command is already ready to read the file as soon as file is made but not closed. I know this may sound lame, but something like this happens when you try to compile sass, concatenate other css and minify them in a single function. In this case, plumber and wait() is a work-around to let things going.

Edited 1 time

May 19, 2017

@FieryCod This is mid of 2017 and yes plumber is a go-away-error kind of tool. Many plugins, particularly gulp-sass throw@import error because file is not ready or unreadable. Whenever sass compiler complies SASS files, dont know how, but it takes more time in pipe and next command is already ready to read the file as soon as file is made but not closed. I know this may sound lame, but something like this happens when you try to compile sass, concatenate other css and minify them in a single function. In this case, plumber and wait() is a work-around to let things going.