Skip to content

Commit

Permalink
fix(config): Simpilfy error proceesing. (#3345)
Browse files Browse the repository at this point in the history
Fixes #3339
  • Loading branch information
johnjbarton committed Jul 26, 2019
1 parent 1489e9a commit 582a406
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
22 changes: 9 additions & 13 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,15 @@ function parseConfig (configFilePath, cliOptions) {
configModule = configModule.default
}
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND' && e.message.includes(configFilePath)) {
log.error(`File ${configFilePath} does not exist!`)
} else {
log.error('Invalid config file!\n ' + e.stack)

const extension = path.extname(configFilePath)
if (extension === '.coffee' && !COFFEE_SCRIPT_AVAILABLE) {
log.error('You need to install CoffeeScript.\n npm install coffeescript --save-dev')
} else if (extension === '.ls' && !LIVE_SCRIPT_AVAILABLE) {
log.error('You need to install LiveScript.\n npm install LiveScript --save-dev')
} else if (extension === '.ts' && !TYPE_SCRIPT_AVAILABLE) {
log.error('You need to install TypeScript.\n npm install typescript ts-node --save-dev')
}
log.error('Error in config file!\n ' + e.stack || e)

const extension = path.extname(configFilePath)
if (extension === '.coffee' && !COFFEE_SCRIPT_AVAILABLE) {
log.error('You need to install CoffeeScript.\n npm install coffeescript --save-dev')
} else if (extension === '.ls' && !LIVE_SCRIPT_AVAILABLE) {
log.error('You need to install LiveScript.\n npm install LiveScript --save-dev')
} else if (extension === '.ts' && !TYPE_SCRIPT_AVAILABLE) {
log.error('You need to install TypeScript.\n npm install typescript ts-node --save-dev')
}
return process.exit(1)
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ describe('config', () => {

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

Expand Down

0 comments on commit 582a406

Please sign in to comment.