gulp-community / gulp-coffee

Coffeescript plugin for gulp
MIT License
226 stars 70 forks source link

Error handler being ignored #59

Open eranimo opened 9 years ago

eranimo commented 9 years ago
coffeeStream = coffee().on('error', (error) ->
    {filename} = error
    extension = path.extname(error.filename)
    dirname = path.dirname(filename)
    basename = path.basename(error.filename, '.coffee')
    target = path.join(dirname, "#{basename}.js")
)

gulp.task("coffee", () ->
    return gulp.src(dedupeGlobs(paths.coffee))
        .pipe(sourcemaps.init())
        .pipe(ngClassify(ngClassifyOptions))
        .pipe(coffeeStream)
        .pipe(ngAnnotate())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(COMPILE_PATH))

I have a syntax error in one of the files being loaded into the task.

The following prints to the console:

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: [stdin]:1:1: error: unexpected &
&*^%$^#&*()_

I've tried adding gulp-plumber, but all it did was prevent gulp from exiting.

yocontra commented 9 years ago

This doesn't work?

handler = (error) ->
    {filename} = error
    extension = path.extname(error.filename)
    dirname = path.dirname(filename)
    basename = path.basename(error.filename, '.coffee')
    target = path.join(dirname, "#{basename}.js")

gulp.task "coffee", ->
    return gulp.src(dedupeGlobs(paths.coffee))
        .pipe(sourcemaps.init())
        .pipe(ngClassify(ngClassifyOptions))
        .pipe(coffeeStream).on('error', handler)
        .pipe(ngAnnotate())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(COMPILE_PATH))
eranimo commented 9 years ago

No it does not. Plumber still catches the unhandled error, but I can't do anything useful with it because its not an error object.

manuel-di-iorio commented 8 years ago

The only way to correctly catch the error with gulp-coffee is using Plumber. Without it, the error is caught only the first time and then the task will stop watching (I mean with gulp.watch)