gulp-coffee icon indicating copy to clipboard operation
gulp-coffee copied to clipboard

Expose path information on failure

Open ide opened this issue 9 years ago • 2 comments

I would like to write an error handler that writes a small JS file when gulp-coffee fails. For example if a.coffee has a syntax error, I want to create a.js with:

throw new Error('Error compiling a.coffee: <syntaxerror.stack>');

For this, my gulp task needs access to the name of the JS file that gulp-coffee was trying to create.

ide avatar Jul 16 '14 04:07 ide

This should get you what you need.

gulpfile.coffee

gulp = require 'gulp'
coffee = require 'gulp-coffee'
path = require 'path'

gulp.task 'compile', ->
  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"

  return gulp.src('src/**/*.coffee')
    .pipe(coffeeStream)
    .pipe(gulp.dest('lib'))

paulyoung avatar Aug 04 '14 02:08 paulyoung

I think the problem here came from CS 1.6 -> 1.7

It used to be 'fileName' which is a semi-standard Error class attributed, and it changed to 'filename' which isn't. I'll see what I can do.

yocontra avatar Aug 04 '14 22:08 yocontra