Skip to content

Commit

Permalink
fix: Report user error with ServerlessError
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Nov 19, 2021
1 parent 8ade442 commit 14a7f12
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ function getExternalModules({ compilation }) {
return Array.from(externals);
}

function webpackCompile(config, logStats) {
function webpackCompile(config, logStats, ServerlessError) {
return BbPromise.fromCallback(cb => webpack(config).run(cb)).then(stats => {
// ensure stats in any array in the case of concurrent build.
stats = stats.stats ? stats.stats : [stats];

_.forEach(stats, compileStats => {
logStats(compileStats);
if (compileStats.hasErrors()) {
throw new Error('Webpack compilation error, see stats above');
throw new ServerlessError('Webpack compilation error, see stats above');
}
});

Expand All @@ -109,9 +109,9 @@ function webpackCompile(config, logStats) {
});
}

function webpackConcurrentCompile(configs, logStats, concurrency) {
return BbPromise.map(configs, config => webpackCompile(config, logStats), { concurrency }).then(stats =>
_.flatten(stats)
function webpackConcurrentCompile(configs, logStats, concurrency, ServerlessError) {
return BbPromise.map(configs, config => webpackCompile(config, logStats, ServerlessError), { concurrency }).then(
stats => _.flatten(stats)
);
}

Expand All @@ -127,11 +127,11 @@ module.exports = {
const logStats = getStatsLogger(configs[0].stats, this.serverless.cli.consoleLog);

if (!this.configuration) {
return BbPromise.reject('Missing plugin configuration');
return BbPromise.reject(new this.serverless.classes.Error('Missing plugin configuration'));
}
const concurrency = this.configuration.concurrency;

return webpackConcurrentCompile(configs, logStats, concurrency).then(stats => {
return webpackConcurrentCompile(configs, logStats, concurrency, this.serverless.classes.Error).then(stats => {
this.compileStats = { stats };
return BbPromise.resolve();
});
Expand Down

0 comments on commit 14a7f12

Please sign in to comment.