Skip to content

Instantly share code, notes, and snippets.

@w0rm
Created May 25, 2015 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w0rm/36ff0b4399a414384690 to your computer and use it in GitHub Desktop.
Save w0rm/36ff0b4399a414384690 to your computer and use it in GitHub Desktop.
Unhandled gulp-postcss errors don't end up in console if not manually catched
var Stream = require('stream')
var gulp = require('gulp')
var postcss = require('gulp-postcss')
function errorStream () {
var stream = new Stream.Transform({ objectMode: true })
stream._transform = function (file, encoding, cb) {
cb(new Error('unhandled exception!'))
}
return stream
}
gulp.task('stream', function () {
gulp.src('package.json')
.pipe(errorStream())
.pipe(gulp.dest('dest'))
})
/*
[11:42:46] Using gulpfile ~/Work/stream-test/gulpfile.js
[11:42:46] Starting 'stream'...
[11:42:46] Finished 'stream' after 5.25 ms
events.js:72
throw er; // Unhandled 'error' event
^
Error: unhandled exception
at Transform.stream._transform (/Users/w0rm/Work/stream-test/gulpfile.js:8:8)
at Transform._read (_stream_transform.js:179:10)
at Transform._write (_stream_transform.js:167:12)
at doWrite (_stream_writable.js:226:10)
at writeOrBuffer (_stream_writable.js:216:5)
at Transform.Writable.write (_stream_writable.js:183:11)
at write (/Users/w0rm/Work/stream-test/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
at flow (/Users/w0rm/Work/stream-test/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
at DestroyableTransform.pipeOnReadable (/Users/w0rm/Work/stream-test/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)
at DestroyableTransform.emit (events.js:92:17)
*/
gulp.task('postcss', function () {
gulp.src('package.json')
.pipe(postcss([function () {}]))
// Error will only be shown if this line is uncommented
//.on('error', console.log)
.pipe(gulp.dest('dest'))
})
/*
[11:44:16] Using gulpfile ~/Work/stream-test/gulpfile.js
[11:44:16] Starting 'postcss'...
[11:44:16] Finished 'postcss' after 5.36 ms
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment