Skip to content

Commit 886d4ec

Browse files
committed
Wrap postcss errors
1 parent 4495fe5 commit 886d4ec

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var through = require('through2')
22
var postcss = require('postcss')
33
var applySourceMap = require('vinyl-sourcemaps-apply')
4+
var gutil = require('gulp-util')
45

56

67
module.exports = function (processors, options) {
@@ -37,7 +38,11 @@ module.exports = function (processors, options) {
3738
opts.map = true
3839
}
3940

40-
result = processor.process(file.contents.toString('utf8'), opts)
41+
try {
42+
result = processor.process(file.contents.toString('utf8'), opts)
43+
} catch (err) {
44+
return cb(new gutil.PluginError('gulp-postcss', err))
45+
}
4146

4247
file.contents = new Buffer(result.css)
4348

test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ it('should transform css with multiple processors', function (cb) {
2727
})
2828

2929

30+
it('should correctly wrap postcss errors', function (cb) {
31+
32+
var stream = postcss([ doubler ])
33+
34+
stream.on('error', function (err) {
35+
assert.ok(err instanceof gutil.PluginError)
36+
assert.equal(err.plugin, 'gulp-postcss')
37+
cb()
38+
})
39+
40+
stream.write(new gutil.File({
41+
contents: new Buffer('a {\n a b {}\n}')
42+
}))
43+
44+
stream.end()
45+
46+
})
47+
48+
3049
function doubler (css) {
3150
css.eachDecl(function (decl) {
3251
decl.parent.prepend(decl.clone())

0 commit comments

Comments
 (0)