Merge pull request #15578 from webpack/feat/catch-error-in-run-as-child
catch error in runAsChild callback
This commit is contained in:
commit
4a0937fdd0
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue