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

catch error in runAsChild callback #15578

Merged
merged 2 commits into from
Apr 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/Compiler.js
Expand Up @@ -545,8 +545,21 @@ class Compiler {
*/
runAsChild(callback) {
const startTime = Date.now();

const finalCallback = (err, entries, compilation) => {
try {
if (err) return callback(err);
callback(null, entries, compilation);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (err) return callback(err);
callback(null, entries, compilation);
callback(err, entries, compilation);

} catch (e) {
const err = new WebpackError(
`compiler.runAsChild callback error: ${e}`
Copy link
Member

Choose a reason for hiding this comment

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

This swallows the stack trace. Maybe add err.details = e.stack

);
this.parentCompilation.errors.push(err);
}
};

this.compile((err, compilation) => {
if (err) return callback(err);
if (err) return finalCallback(err);

this.parentCompilation.children.push(compilation);
for (const { name, source, info } of compilation.getAssets()) {
Expand All @@ -561,7 +574,7 @@ class Compiler {
compilation.startTime = startTime;
compilation.endTime = Date.now();

return callback(null, entries, compilation);
return finalCallback(null, entries, compilation);
});
}

Expand Down