Skip to content

Commit 582a406

Browse files
authored
fix(config): Simpilfy error proceesing. (#3345)
Fixes #3339
1 parent 1489e9a commit 582a406

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

lib/config.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,15 @@ function parseConfig (configFilePath, cliOptions) {
353353
configModule = configModule.default
354354
}
355355
} catch (e) {
356-
if (e.code === 'MODULE_NOT_FOUND' && e.message.includes(configFilePath)) {
357-
log.error(`File ${configFilePath} does not exist!`)
358-
} else {
359-
log.error('Invalid config file!\n ' + e.stack)
360-
361-
const extension = path.extname(configFilePath)
362-
if (extension === '.coffee' && !COFFEE_SCRIPT_AVAILABLE) {
363-
log.error('You need to install CoffeeScript.\n npm install coffeescript --save-dev')
364-
} else if (extension === '.ls' && !LIVE_SCRIPT_AVAILABLE) {
365-
log.error('You need to install LiveScript.\n npm install LiveScript --save-dev')
366-
} else if (extension === '.ts' && !TYPE_SCRIPT_AVAILABLE) {
367-
log.error('You need to install TypeScript.\n npm install typescript ts-node --save-dev')
368-
}
356+
log.error('Error in config file!\n ' + e.stack || e)
357+
358+
const extension = path.extname(configFilePath)
359+
if (extension === '.coffee' && !COFFEE_SCRIPT_AVAILABLE) {
360+
log.error('You need to install CoffeeScript.\n npm install coffeescript --save-dev')
361+
} else if (extension === '.ls' && !LIVE_SCRIPT_AVAILABLE) {
362+
log.error('You need to install LiveScript.\n npm install LiveScript --save-dev')
363+
} else if (extension === '.ts' && !TYPE_SCRIPT_AVAILABLE) {
364+
log.error('You need to install TypeScript.\n npm install typescript ts-node --save-dev')
369365
}
370366
return process.exit(1)
371367
}

test/unit/config.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ describe('config', () => {
118118

119119
expect(logSpy).to.have.been.called
120120
const event = logSpy.lastCall.args
121-
expect(event).to.be.deep.equal(['File /conf/not-exist.js does not exist!'])
121+
expect(event.toString().split('\n').slice(0, 2)).to.be.deep.equal(
122+
[`Error in config file!`, ` Error: Cannot find module '/conf/not-exist.js'`])
122123
expect(mocks.process.exit).to.have.been.calledWith(1)
123124
})
124125

0 commit comments

Comments
 (0)