Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ const cliConfig = {
try {
return require(plugin)()
} catch (e) {
return error(`Plugin Error: Cannot find module '${plugin}'`)
const msg = e.message || `Cannot find module '${plugin}'`
let prefix = msg.includes(plugin) ? '' : ` (${plugin})`
if (e.name && e.name !== 'Error') prefix += `: ${e.name}`
return error(`Plugin Error${prefix}: ${msg}'`)
}
})
: []
Expand Down
15 changes: 14 additions & 1 deletion test/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test.failing('invalid --config', t => {
})
})

test('PluginError', t => {
test('plugin not found', t => {
return cli(['test/fixtures/a.css', '-u', 'postcss-plugin', '-o', tmp()]).then(
({ err, code }) => {
t.is(code, 1, 'expected non-zero error code')
Expand All @@ -52,6 +52,19 @@ test('PluginError', t => {
)
})

test('plugin throws on require', t => {
return cli([
'test/fixtures/a.css',
'-u',
'./test/fixtures/bad-plugin',
'-o',
tmp()
]).then(({ err, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(err.toString(), /Plugin Error \(.*bad-plugin\): This fails/)
})
})

test('CssSyntaxError', t => {
return cli(['test/fixtures/a.css', '--parser', 'sugarss', '-o', tmp()]).then(
({ err, code }) => {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/bad-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('This fails')