pkozlowski.opensource
pkozlowski.opensource

Reputation: 117370

Marking async task as failed and have gulp exit with non-zero exit code

Consider this simple async gulp task (this is obviously not a real-life task but nicely illustrates a general problem of marking async tests as failed):

gulp.task('foo', function (done) {
    setTimeout(function () {
        //HERE: how to fail the gulp run and have it exit wit non-zero status?
    }, 1000);
});

I would like to know how to mark the foo task as failed so Gulp aborts the build and return non-zero exit code status to the shell. The things I've tried:

What would be an idiomatic way of marking such an async task as failed?

Upvotes: 3

Views: 1810

Answers (1)

pkozlowski.opensource
pkozlowski.opensource

Reputation: 117370

It turned out to be a bug in the gulp itself that was fixed in the version 3.8.4 via https://github.com/gulpjs/gulp/commit/d8d7542f58046f15d88795e3c48f952f54a02c3c

Starting from 3.8.4 one can write:

gulp.task('foo', function (done) {
    setTimeout(function () {
        done('error');
    }, 1000);
});

and have gulp properly exiting process with the return status 1.

Upvotes: 3

Related Questions