Merge pull request #15578 from webpack/feat/catch-error-in-run-as-child

catch error in runAsChild callback
This commit is contained in:
Tobias Koppers 2022-04-01 15:26:01 +02:00 committed by GitHub
commit 4a0937fdd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -545,8 +545,21 @@ class Compiler {
*/
runAsChild(callback) {
const startTime = Date.now();
const finalCallback = (err, entries, compilation) => {
try {
callback(err, entries, compilation);
} catch (e) {
const err = new WebpackError(
`compiler.runAsChild callback error: ${e}`
);
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()) {
@ -561,7 +574,7 @@ class Compiler {
compilation.startTime = startTime;
compilation.endTime = Date.now();
return callback(null, entries, compilation);
return finalCallback(null, entries, compilation);
});
}