From 582a406aa124a39ed57fc54673b73ca9cf808ae7 Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Fri, 26 Jul 2019 16:41:15 -0700 Subject: [PATCH] fix(config): Simpilfy error proceesing. (#3345) Fixes #3339 --- lib/config.js | 22 +++++++++------------- test/unit/config.spec.js | 3 ++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/config.js b/lib/config.js index 67f05d1b8..b69c73a41 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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) } diff --git a/test/unit/config.spec.js b/test/unit/config.spec.js index e0f16c5b0..c7a5270e1 100644 --- a/test/unit/config.spec.js +++ b/test/unit/config.spec.js @@ -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) })