Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure errors in webpack.run callback always reject #838

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions packages/webpack/src/ember-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,27 +443,29 @@ const Webpack: PackagerConstructor<Options> = class Webpack implements Packager
private runWebpack(webpack: webpack.MultiCompiler): Promise<webpack.StatsCompilation> {
return new Promise((resolve, reject) => {
webpack.run((err, stats) => {
if (err) {
if (stats) {
try {
if (err) {
if (stats) {
this.consoleWrite(stats.toString());
}
throw err;
}
if (!stats) {
// this doesn't really happen, but webpack's types imply that it
// could, so we just satisfy typescript here
throw new Error('bug: no stats and no err');
}
if (stats.hasErrors()) {
// the typing for MultiCompiler are all foobared.
throw this.findBestError(flatMap((stats as any).stats, s => s.compilation.errors));
}
if (stats.hasWarnings() || process.env.VANILLA_VERBOSE) {
this.consoleWrite(stats.toString());
}
reject(err);
return;
}
if (!stats) {
// this doesn't really happen, but webpack's types imply that it
// could, so we just satisfy typescript here
throw new Error('bug: no stats and no err');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what lead me here, but in general try/catch in these async promise resolvers is best practice. Avoiding dropped errors, and breaking the implied contract of the wrapping promise

}
if (stats.hasErrors()) {
// the typing for MultiCompiler are all foobared.
reject(this.findBestError(flatMap((stats as any).stats, s => s.compilation.errors)));
return;
}
if (stats.hasWarnings() || process.env.VANILLA_VERBOSE) {
this.consoleWrite(stats.toString());
resolve(stats.toJson());
} catch (e) {
reject(e);
}
resolve(stats.toJson());
});
});
}
Expand Down