gulp icon indicating copy to clipboard operation
gulp copied to clipboard

Watch stops on errors (Figure out better error handling)

Open yocontra opened this issue 12 years ago • 58 comments

This is spread around 10 issues on all sorts of projects. I'm consolidating them all here.

yocontra avatar Feb 10 '14 15:02 yocontra

Watch waits for end, so emitting end in error handler solves most of the cases.

function handleError(err) {
  console.log(err.toString());
  this.emit('end');
}

gulp.task('onerror', function () {
  return gulp.src('somefile')
    .pipe(someStream())
    .on('error', handleError);
});

gulp.task('plumber', function () {
  return gulp.src('somefile')
    .pipe(pulmber({ errorHandler: handleError }))
    .pipe(someStream());
});

gulp.task('multipipe', function () {
  return multipipe(
    gulp.src('somefile'),
    someStream()
  ).on('error', handleError);
});

(We don't need errorHandler for plumber if all plugins are written like the example in the guideline. In that case, plumber suppresses error and end is emitted somehow. However, for callback(err) of through2, plumber suppresses error but end is not emitted.)

While those tasks work well with watch, they always exit with 0, which is problematic in Continuous Integration and such.

shuhei avatar Feb 11 '14 04:02 shuhei

Important issue IMHO, as this really slows my development time currently.

I think we should be able to mark task as failed but still run it.

  • gulp watch task could ignore this error (only log it in console) and keep running.
  • default behaviour would be to console.log(err); process.exit(1) - so task initted in CLI would simply fail.

But this would make it dependant on robrich/orchestrator#20

jtomaszewski avatar Feb 28 '14 12:02 jtomaszewski

Yes, I'm getting a ton of issues about this...

sindresorhus avatar Feb 28 '14 15:02 sindresorhus

While the issue feels a lot more general than watch I'm glad this is on the radar. I just finished my first gulp flow (v0.1, anyway) and I'm firing up express instances and watching. A single typo in a scss file kills express instances and lr just as much as watch…

I know, not constructive.

irrg avatar Feb 28 '14 15:02 irrg

My pitch was a flag one could pass into .run() (or whatever we rename it to) that doesn't stop on errors at all, just pass the error to the callback. Watch could then call it with the flag set, and everything else could call it with the flag unset. I see how robrich/orchestrator#20 is quite similar though -- good call.

robrich avatar Feb 28 '14 20:02 robrich

Is there any progress, it takes too much time.

jarvys avatar Mar 15 '14 11:03 jarvys

@phated @robrich Progress update on the next orchestrator?

yocontra avatar Mar 15 '14 14:03 yocontra

Check out orchestrator's develop branch and github.com/robrich/gulp develop branch. Give it a whirl and see if it's sufficient.

robrich avatar Mar 16 '14 05:03 robrich

Consolidating into

https://github.com/gulpjs/gulp/issues/358 https://github.com/gulpjs/gulp/issues/355

yocontra avatar Mar 20 '14 01:03 yocontra

Just a quick update: I was waiting until the new task system in gulp 4.0 for this to be fixed but it seems to be a large enough issue that I put a hotfix in place in 3.6. Watch will no longer stop and the process will no longer exit just because an error was thrown.

yocontra avatar Mar 28 '14 05:03 yocontra

Hi, I'm relatively new to gulp, but I've updated to the latest version (3.6) and gulp-ruby-sass (0.2.0) is still stopping the watch task when a syntax error occurs:

[gulp] Error in plugin 'gulp-ruby-sass': 
Syntax error: Invalid CSS after " */": expected "}", was ""
        on line 51 of /Users/matt/Git/client/_dev/scss/style.scss

    at ChildProcess.<anonymous> (/Users/matt/Git/client/node_modules/gulp-ruby-sass/index.js:73:25)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

What other details do I need to provide to be of use?

mattkersley avatar Apr 01 '14 19:04 mattkersley

@mattkersley your CLI and local version are up to date with 3.6?

yocontra avatar Apr 01 '14 22:04 yocontra

@contra your update in 3.6.0 (both local and cli version) didn't help me. I use jshint to validate my files:

gulp.task('js', function() {
    return gulp.src('src/**/*.js')
        .pipe(jshint('.jshintrc'))
        .pipe(jshint.reporter('jshint-stylish'))
        .pipe(jshint.reporter('fail'))
        .pipe(concat('public/scripts.js'));
});
gulp.task('watch', function () {
    gulp.watch('src/**/*.js', ['js']);
});

Gulp exits from watch every time, when it has found a syntax error with the following stacktrace:

throw err
              ^
Error: JSHint failed for app/app.js
    at /home/just-boris/coding/tms/node_modules/gulp-jshint/src/reporters.js:8:15
    at wrappedMapper (/home/just-boris/coding/tms/node_modules/gulp-jshint/node_modules/map-stream/index.js:76:19)
    at Stream.stream.write (/home/just-boris/coding/tms/node_modules/gulp-jshint/node_modules/map-stream/index.js:88:21)
    at Stream.ondata (stream.js:51:26)
    at Stream.EventEmitter.emit (events.js:104:17)

Is there a way to run watch continuously and to can start again after the error?

just-boris avatar Apr 02 '14 15:04 just-boris

Remove the line:

jshint.reporter("fail")

On Apr 2, 2014, at 11:30 AM, Boris Serdyuk [email protected] wrote:

@contra your update in 3.6.0 (both local and cli version) didn't help me. I use jshint to validate my files:

gulp.task('js', function() { return gulp.src('src//*.js') .pipe(jshint('.jshintrc')) .pipe(jshint.reporter('jshint-stylish')) .pipe(jshint.reporter('fail')) .pipe(concat('public/scripts.js')); }); gulp.task('watch', function () { gulp.watch('src//*.js', ['js']); }); Gulp exits from watch every time, when it has found a syntax error with the following stacktrace:

throw err ^ Error: JSHint failed for app/app.js at /home/just-boris/coding/tms/node_modules/gulp-jshint/src/reporters.js:8:15 at wrappedMapper (/home/just-boris/coding/tms/node_modules/gulp-jshint/node_modules/map-stream/index.js:76:19) at Stream.stream.write (/home/just-boris/coding/tms/node_modules/gulp-jshint/node_modules/map-stream/index.js:88:21) at Stream.ondata (stream.js:51:26) at Stream.EventEmitter.emit (events.js:104:17) Is there a way to run watch continuously and to can start again after the error?

— Reply to this email directly or view it on GitHub.

jasonrhodes avatar Apr 02 '14 16:04 jasonrhodes

hmmm... possibly not... how do I go about updating my cli version? (sorry for the newbie question)

I've run npm install gulp -g, but when I run npm gulp -v I'm not getting 3.6.0.

mattkersley avatar Apr 02 '14 17:04 mattkersley

never mind... just did the following:

gulp -v
[gulp] CLI version 3.6.0
[gulp] Local version 3.6.0

So both up to date, still breaks when syntax errors occur :(

Edit: Here is my gulpfile for reference - https://gist.github.com/mattkersley/9939822

mattkersley avatar Apr 02 '14 17:04 mattkersley

@jasonrhodes yes, the error will be removed. But it means that I wouldn't know about an error, for example, in travis. So, this reporter is required here, and my issue like the @mattkersley case.

just-boris avatar Apr 02 '14 18:04 just-boris

@mattkersley Not sure what's going on regarding your situation and the potential fix in 3.6 but as a temporary work around I set up my lint task like this (i.e. manually check for the fail and only beep if it occurs, this way it should operate quite happily when called from a watch): https://github.com/spenceralger/gulp-jshint/pull/30#issuecomment-37769838

jedrichards avatar Apr 02 '14 18:04 jedrichards

@contra I'm updated to the latest version 3.6.0, but watch is still exiting on browserify errors.

TimothyKrell avatar Apr 03 '14 13:04 TimothyKrell

@contra hey man, did you have a chance to check out my gulp config? any ideas why the fix isn't working for me?

Cheers.

mattkersley avatar Apr 07 '14 07:04 mattkersley