Skip to content

Commit

Permalink
Merge pull request #1011 from medikoo/1122-improve-error-handling
Browse files Browse the repository at this point in the history
Fix handling of multiple compilation errors
  • Loading branch information
j0k3r committed Nov 23, 2021
2 parents a6a83f6 + 73c20cb commit a8688ce
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function webpackCompile(config, logStats, ServerlessError) {
_.forEach(stats, compileStats => {
logStats(compileStats);
if (compileStats.hasErrors()) {
throw new ServerlessError('Webpack compilation error, see stats above');
throw _.assign(new ServerlessError('Webpack compilation error, see stats above'), { stats: compileStats });
}
});

Expand All @@ -99,9 +99,22 @@ function webpackCompile(config, logStats, ServerlessError) {
}

function webpackConcurrentCompile(configs, logStats, concurrency, ServerlessError) {
return BbPromise.map(configs, config => webpackCompile(config, logStats, ServerlessError), { concurrency }).then(
stats => _.flatten(stats)
);
const errors = [];
return BbPromise.map(
configs,
config =>
webpackCompile(config, logStats, ServerlessError).catch(error => {
errors.push(error);
return error.stats;
}),
{ concurrency }
).then(stats => {
if (errors.length) {
if (errors.length === 1) throw errors[0];
throw new ServerlessError('Webpack compilation errors, see stats above');
}
return _.flatten(stats);
});
}

module.exports = {
Expand Down

0 comments on commit a8688ce

Please sign in to comment.