Skip to content

Commit b1d48e1

Browse files
committed
A better error handling inside the isChunk(..) function
In case when the build failed due to an error during building of some module, this change ensures that plugin throws the original error, rather than creates a new Error with a non-specific message.
1 parent 6d68cef commit b1d48e1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,19 @@ function getPath(compilation, source, chunk) {
356356

357357
function isChunk(chunk, error) {
358358
if (!(chunk instanceof Chunk)) {
359-
throw new Error(typeof error === 'string' ? error : 'chunk is not an instance of Chunk');
359+
/* If the entry module failed to build, throw the error that caused it. */
360+
var e = chunk && chunk.entryModule && chunk.entryModule.error;
361+
if (e) throw e;
362+
363+
/* If any of dependency modules failed to build, throw the first found
364+
* error that caused it. */
365+
chunk._modules.forEach((m) => {
366+
if (m.error) throw m.error;
367+
});
368+
369+
/* Otherwise throw an error with the error message passed in, or with
370+
* the fallback error message. */
371+
throw new Error(typeof error === 'string' ? error : 'chunk is not an instance of Chunk');
360372
}
361373

362374
return true;

0 commit comments

Comments
 (0)