Skip to content

Commit

Permalink
#21 do not output js stack trace for css syntax error
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rm committed Apr 12, 2015
1 parent b70d644 commit 7400cc2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var postcss = require('postcss')
var applySourceMap = require('vinyl-sourcemaps-apply')
var gutil = require('gulp-util')
var path = require('path')
var CssSyntaxError = require('postcss/lib/css-syntax-error')


module.exports = function (processors, options) {

Expand Down Expand Up @@ -67,6 +69,11 @@ module.exports = function (processors, options) {
}

function handleError (error) {
var errorOptions = { fileName: file.path }
if (error instanceof CssSyntaxError) {
error = error.message + error.showSourceCode()
errorOptions.showStack = false
}
cb(new gutil.PluginError('gulp-postcss', error))
}

Expand Down
29 changes: 29 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ it('should correctly generate relative source map', function (cb) {
describe('PostCSS Guidelines', function () {

var sandbox = sinon.sandbox.create()
var CssSyntaxError = function (message, sourceCode) {
this.message = message
this.sourceCode = sourceCode
this.showSourceCode = function () {
return this.sourceCode
}
}
var postcssStub = {
use: sandbox.stub()
, process: sandbox.stub()
Expand All @@ -123,6 +130,7 @@ describe('PostCSS Guidelines', function () {
postcss: function () {
return postcssStub
}
, 'postcss/lib/css-syntax-error': CssSyntaxError
})


Expand Down Expand Up @@ -151,6 +159,27 @@ describe('PostCSS Guidelines', function () {

})


it('should not output js stack trace for `CssSyntaxError`', function (cb) {

var stream = postcss([ doubler ])
var cssSyntaxError = new CssSyntaxError('message', 'sourceCode')
postcssStub.process.returns(Promise.reject(cssSyntaxError))

stream.on('error', function (error) {
assert.equal(error.showStack, false)
assert.equal(error.message, 'message' + 'sourceCode')
cb()
})

stream.write(new gutil.File({
contents: new Buffer('a {}')
}))

stream.end()

})

})


Expand Down

0 comments on commit 7400cc2

Please sign in to comment.