Create clearer example on ignoring errors for watch mode #27

Closed
firstdoit opened this Issue Feb 26, 2014 · 3 comments

Comments

2 participants

I was battling the fact that gulp crashes when gulp-mocha throws an error.

I have suffered quite a bit until stumbling upon this blessed SO question which guided me to emit "end" on the error handler in order to enable gulp to keep running.

I guess we could make it clearer that if you are running in some sort of watch mode you must "eat up" the error. My gulpfile ended up like this:

gulp = require 'gulp'
nodemon = require 'gulp-nodemon'
mocha = require 'gulp-mocha'
runningNodemon = false

gulp.task "test", ->
  gulp.src("test/**/*.coffee")
  .pipe(mocha(reporter: 'spec', compilers: "coffee:coffee-script/register"))
  .on('error', (e) -> console.log e.toString(); @emit 'end' if runningNodemon) # Eat up this error to continue running

gulp.task "nodemon", ->
  runningNodemon = true
  stream = nodemon script: "app.coffee", ext: "coffee", ignore: "gulpfile.coffee"
  stream.on("restart", ["test"])

gulp.task "default", ["test", "nodemon"]

I have created the boolean runningNodemon in order to emit the correct exit code in case of running a simple gulp test.

I have tried using gutil.log and it did not stop the error from propagating... Will try again.

@sindresorhus Yep, gutil.log does not stop the error from propagating.

I must still use this.emit('end') in order to prevent gulp from crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment