brent_white
brent_white

Reputation: 1019

gulp-plumber throws error then stops build.

Having an issue with gulp-plumber as it breaks my build upon a error throw.

For example I make a change to my scss with an invalid syntax such as padding-left:woah-err. Plumber notifies me in the terminal of the error. Then I got back to scss file make the change to padding-left:20px; save and get no response in terminal and it looks like my gulp build is broken...To fix I haft to restart gulp.

However inside my gulp file if I change this.emit('end'); to this.emit(); the build dose not break but I get no plumber notifications of errors anymore.

Looking into changing up the way my I configured my plumber to get this to work right. Any suggestions? This looks like a good solution.

Here's my packages

var gulp = require('gulp'),
 fs = require('fs'),
 gulpif = require('gulp-if'), // condtionally run task
 plumber = require('gulp-plumber'), // prevent pipe breaking
 browserSync = require('browser-sync').create(),
 bower = require('gulp-bower'), // gulp bower
 concat = require('gulp-concat'), // concat files
 cssmin = require('gulp-minify-css'), // minify css
 rename = require('gulp-rename'), // rename file
 runSequence = require('run-sequence'), // runs gulp tasks in order
 sass = require('gulp-sass'), // css preprocessor
 uglify = require('gulp-uglify'); // minify js

Here's my styles task (had someone help me set this up)..Might want to rethink it's structure. Open to suggestions

// Styles Task
gulp.task('styles', function(){
    // streamError is set to false
    var streamError = false;
    return gulp.src(paths.source.styles)
        .pipe(plumber({
            // plumber finds errors in stream
            errorHandeler:function(error){
                streamError = error;
                // plumber logs errors to console and terminal
                console.log(streamError.message);
                browserSync.notify(streamError.message,errorTimeout);
                this.emit('end');
            }
        }))
        .pipe(sass())
         // compile sass
        .pipe(gulp.dest(paths.destination.styles))
        // if the streamError is NOT false reload browser
        .pipe(gulpif(!streamError,browserSync.reload({stream:true})))
        .pipe(cssmin()) // min css
        .pipe(rename({ // rename file to site.min.css
            suffix:'.min'
        }))
        .pipe(gulp.dest(paths.destination.styles))
        // if streamError is not `false` reload browser
        .pipe(gulpif(!streamError,browserSync.reload({stream:true})));
});

Here's the error enter image description here

Upvotes: 0

Views: 1013

Answers (2)

Pisandelli
Pisandelli

Reputation: 403

This fixed the problem for me.

Using gulp-plumber 1.1.0

function onError(err) {
    console.log(err); //or other way you may prefer to log
    this.emit('end');
}

gulp.task('myTask', function(){
    return gulp
    .src('myFilePath')
    .pipe(plumber(onError))
    [...]
}

Hope this help

Upvotes: 1

Eric Chen
Eric Chen

Reputation: 3708

I think because when error happens, Gulp didnt receive the finished callback;
You may need add a done param to your task function.
if there is error, you will call done() manually. Simple:

// Styles Task
gulp.task('styles', function( done /** done! **/){
    // streamError is set to false
    var streamError = false;
    return gulp.src(paths.source.styles)
        .pipe(plumber({
            // plumber finds errors in stream
            errorHandeler:function(error){
                streamError = error;
                // plumber logs errors to console and terminal
                console.log(streamError.message);
                browserSync.notify(streamError.message,errorTimeout);
                this.emit('end');
                done();//call done here!
            }
        }))
        //keep the same.....
});

hope it's help

Upvotes: 0

Related Questions