Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create clearer example on ignoring errors for watch mode #27

Closed
guifromrio opened this issue Feb 26, 2014 · 3 comments
Closed

Create clearer example on ignoring errors for watch mode #27

guifromrio opened this issue Feb 26, 2014 · 3 comments

Comments

@guifromrio
Copy link

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.

@sindresorhus
Copy link
Owner

@guifromrio
Copy link
Author

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

@guifromrio
Copy link
Author

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants