From ea48b52c6adbb9ae480201033485918245696805 Mon Sep 17 00:00:00 2001 From: Frank Schmid Date: Thu, 21 Sep 2017 12:38:14 +0200 Subject: [PATCH 1/2] Log errors in webpack config explicitly. --- lib/validate.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/validate.js b/lib/validate.js index 1983a65d6..1c762fd71 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -99,7 +99,12 @@ module.exports = { throw new this.serverless.classes .Error('The webpack plugin could not find the configuration file at: ' + webpackConfigFilePath); } - this.webpackConfig = require(webpackConfigFilePath); + try { + this.webpackConfig = require(webpackConfigFilePath); + } catch (err) { + this.serverless.cli.log(`Could not load webpack config '${webpackConfigFilePath}'`); + return BbPromise.reject(err); + } } // Default context From fc3569440d90eeed6784514f19921056531a2289 Mon Sep 17 00:00:00 2001 From: Frank Schmid Date: Thu, 21 Sep 2017 13:28:54 +0200 Subject: [PATCH 2/2] Added unit test --- tests/validate.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/validate.test.js b/tests/validate.test.js index 86683685c..1e6d6c3bd 100644 --- a/tests/validate.test.js +++ b/tests/validate.test.js @@ -223,6 +223,16 @@ describe('validate', () => { return null; }); }); + + it('should fail when importing a broken configuration file', () => { + const testConfig = 'invalid.webpack.config.js'; + const testServicePath = 'testpath'; + module.serverless.config.servicePath = testServicePath; + module.serverless.service.custom.webpack = testConfig; + serverless.utils.fileExistsSync = sinon.stub().returns(true); + return expect(module.validate()).to.be.rejected + .then(() => expect(serverless.cli.log).to.have.been.calledWith(sinon.match(/^Could not load webpack config/))); + }); }); describe('lib', () => {