Skip to content

Commit

Permalink
Merge pull request #1005 from medikoo/1119-improve-error-reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r authored Nov 19, 2021
2 parents 44dc73e + a542ec4 commit d70f9cb
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 @@ -79,15 +79,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 @@ -98,9 +98,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 @@ -116,11 +116,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 d70f9cb

Please sign in to comment.