From 449d1786c2e253f7f725bd85dc4f4246f81f397d Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Wed, 23 Mar 2022 18:41:16 +0300 Subject: [PATCH 1/2] catch error in runAsChild callback --- lib/Compiler.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Compiler.js b/lib/Compiler.js index bd7474d8f..44712d492 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -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); + } catch (e) { + const err = new WebpackError( + `compiler.runAsChild callback error: ${e}` + ); + 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); }); } From 3929e688a4eb169f0698dece4120adc0f7bc77f3 Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Mon, 28 Mar 2022 15:37:52 +0300 Subject: [PATCH 2/2] fix discussions --- lib/Compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Compiler.js b/lib/Compiler.js index 44712d492..2bdd15b99 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -548,12 +548,12 @@ class Compiler { const finalCallback = (err, entries, compilation) => { try { - if (err) return callback(err); - callback(null, entries, compilation); + callback(err, entries, compilation); } catch (e) { const err = new WebpackError( `compiler.runAsChild callback error: ${e}` ); + err.details = e.stack; this.parentCompilation.errors.push(err); } };