Beetroot Paul
Beetroot Paul

Reputation: 101

gulp-less task exits with zero on invalid styles

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.

Versions:

Upvotes: 2

Views: 365

Answers (1)

Sven Schoenung
Sven Schoenung

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

Related Questions