Skip to content

Commit 44e7d88

Browse files
author
刘祺
committed
Modify, according to @w0rm ‘s opinion
1 parent d765342 commit 44e7d88

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

index.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,19 @@ module.exports = function (processors, options) {
7474
}
7575

7676
function handleError (error) {
77-
var errorOptions = { fileName: file.path }
78-
if (error instanceof Object) {
77+
var errorOptions = { fileName: file.path, showStack: true }
78+
if (error.name === 'CssSyntaxError') {
7979
errorOptions.error = error
80-
if (error.name === 'CssSyntaxError') {
81-
var input = error.input || {};
82-
errorOptions.fileName = error.file || input.file || file.path
83-
errorOptions.lineNumber = error.line || input.line
84-
errorOptions.showStack = false
85-
errorOptions.showProperties = false
86-
error = error.message + '\n\n' + error.showSourceCode() + '\n'
87-
} else {
88-
errorOptions.showStack = true
89-
error = error.message || error
90-
}
80+
errorOptions.fileName = error.file || file.path
81+
errorOptions.lineNumber = error.line
82+
errorOptions.showProperties = false
83+
errorOptions.showStack = false
84+
error = error.message + '\n\n' + error.showSourceCode() + '\n'
9185
}
9286
// Prevent stream’s unhandled exception from
9387
// being suppressed by Promise
9488
setImmediate(function () {
95-
cb(new gutil.PluginError('gulp-postcss', String(error), errorOptions))
89+
cb(new gutil.PluginError('gulp-postcss', error, errorOptions))
9690
})
9791
}
9892

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ it('should respond with error on stream files', function (cb) {
7676
stream.on('error', function (err) {
7777
assert.ok(err instanceof gutil.PluginError)
7878
assert.equal(err.plugin, 'gulp-postcss')
79+
assert.equal(err.showStack, true)
7980
assert.equal(err.message, 'Streams are not supported!')
8081
assert.equal(err.fileName, path.resolve('testpath'))
8182
cb()

0 commit comments

Comments
 (0)