floatdrop / gulp-plumber

Fixing Node pipes
MIT License
806 stars 32 forks source link

Stopping dependent task, but not gulp #27

Open callumacrae opened 9 years ago

callumacrae commented 9 years ago

I have the two following tasks:

gulp.task('js-quality', function () {
  return gulp.src('./src/js/**/*.js')
    .pipe(plugins.plumber({ errorHandler: onError }))
    .pipe(plugins.jscs())
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter(stylish));
});

gulp.task('js', ['js-quality'], function () {
  var bundler = browserify('./src/js/test.js');

  return bundler.bundle()
    .on('error', console.log.bind(console, 'Browserify Error'))
    .pipe(source('bundle.js'))
    .pipe(gulp.dest('./demo/build'));
});

When js-quality fails, I want onError to be called (which pipes the error through to browser-sync and beeps), but I don't want the js task to run.

Is there any way to do this, or is this something I'll have to work around until Gulp 4?

floatdrop commented 9 years ago

@callumacrae you can try to reemit error event from onError handler. Or you can try to use callback version of js-quality task:

gulp.task('js-quality', function (cb) {
 gulp.src('./src/js/**/*.js')
    .pipe(plugins.plumber(function (err) { onError(err); cb(err); } ))
    .pipe(plugins.jscs())
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter(stylish))
    .on('end', cb);
});
ivan-kleshnin commented 9 years ago

I wonder how to make this work too. Reemitting error event from handler leads to infinite recursions. In cb version, callbacks will be called multiple times. The only workaround to connect such tasks I found is global variables...

pikeas commented 9 years ago

+1 for the right way to do this, preferably compatible with Gulp4.

vonagam commented 8 years ago

In Gulp 3 you can call 'this.destroy()' in plumber error handler to prevent 'end' event from firing.

.pipe( plugins.plumber( { errorHandler: function ( error ) { 
  onError( error );
  this.destroy();
 } } ) )