Reputation: 101
Firstly, here is a repo with very simple example of my problem: https://github.com/nkoder/example-of-gulp-less-zero-exit-on-error
I want to define gulp build pipeline which fails on any error. This pipeline would be used in automated process (eg. Continuous Integration) so I need the build command to return non-zero exit code on failure. It works for me with invalid Jade templates or non-passing tests run with Karma.
The problem is when I use gulp-less
to prepare CSS from LESS. Whenever I add any pipeline step after gulp-less
execution, all errors are "consumed" and the whole task exits with 0. But it shouldn't.
wrong
task to fail with non-zero exit code? (solved, see answer below)error
event emitted in less()
call followed by piped stream is not making a whole task to return non-zero exit code? Non-zero is returned in some other similar cases, eg. in Jade or ESLint failure. (not solved yet)Versions:
Upvotes: 2
Views: 365
Reputation: 30564
Listen for the error
event and then exit the process explicitly:
gulp.task('wrong', function () {
return gulp
.src('invalid-styles.less')
.pipe(less().on('error', function(error) {
console.log(error.message);
process.exit(1);
}))
.pipe(gulp.dest('generated-styles.css'));
});
Upvotes: 1