Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail reporter doesn't stop the following tasks when using plumber #121

Open
ghost opened this issue Sep 29, 2015 · 2 comments
Open

Fail reporter doesn't stop the following tasks when using plumber #121

ghost opened this issue Sep 29, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 29, 2015

Hi I have an issue with the fail reporter. My use case is that I want jshint to make the task fail so the following pipes and tasks are not executed but I am also using it inside a watch and I don't want the watch to stop working on failure. I've managed to reach that behaviour for less files but it doesn't work with jshint.

// Error handlers
var onError = function(error) {
    notify.onError({
        message: error.message
    })(error);
    this.emit('end');
};

// JS validation
gulp.task('jshint', function() {
    return gulp
        .src(paths.jsDev + '/**/*.js')
        .pipe(plumber({errorHandler: onError}))
        .pipe(jshint())
        .pipe(jshint.reporter(stylish))
        .pipe(jshint.reporter('fail'));
});

// JS build
gulp.task('js', ['jshint'], function() {
    return gulp
        .src([
            paths.bowerComp + '/fancybox/source/jquery.fancybox.pack.js',
            paths.jsDev + '/**/*.js'
        ])
        .pipe(plumber({errorHandler: onError}))
        .pipe(concat('script.js'))
        .pipe(uglify())
        .pipe(gulp.dest(paths.js));
});

// Watch
gulp.task('watch', function() {

    // Watch .js files
    gulp.watch(paths.jsDev + '/**/*.js', ['js']);
});

So basically on failure the "js" task shouldn't be executed but the watch should keep working.

But this is the output I get:

$ gulp js
[13:36:44] Using gulpfile ~/PhpStorm/Projects/****/gulpfile.js
[13:36:44] Starting 'jshint'...

/****/src/js/script.js
  line 24  col 53  Missing semicolon.

  ⚠  1 warning

[13:36:44] gulp-notify: [Error running Gulp] JSHint failed for: /****/src/js/script.js
[13:36:44] Finished 'jshint' after 100 ms
[13:36:44] Starting 'js'...
[13:36:44] Finished 'js' after 651 ms
@spalger
Copy link
Owner

spalger commented Sep 30, 2015

I'm open to suggestions on how this should work. How did you get it to work with your less task?

@ghost
Copy link
Author

ghost commented Sep 30, 2015

Well I'm far from being a Gulp or Node.js expert. Just using it in my web development workflow.

Here is my less task if it can help you:

// CSS
gulp.task('less', function() {
    return gulp.src(paths.less + '/style.less')
        .pipe(plumber({errorHandler: onError}))
        .pipe(less())
        .pipe(autoprefixer('> 1%', 'last 2 versions', 'ie >= 8'))
        .pipe(minifycss(minifyOptions))
        .pipe(gulp.dest(paths.css));
});

// Watch
gulp.task('watch', function() {

    // Watch .less files
    gulp.watch(paths.less + '/**/*.less', ['less']);

    // Watch .js files
    gulp.watch(paths.jsDev + '/**/*.js', ['js']);
});

In this case if the less() call fails, the following pipe (autoprefixer) is not executed but the watch task keeps working. I'm handling the error the same way as with the jshint task so I guess the errors are not triggered the same way by the less plugin and your plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant