Skip to content

A better error handling inside the isChunk(..) function #58

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,19 @@ function getPath(compilation, source, chunk) {

function isChunk(chunk, error) {
if (!(chunk instanceof Chunk)) {
throw new Error(typeof error === 'string' ? error : 'chunk is not an instance of Chunk');
/* If the entry module failed to build, throw the error that caused it. */
var e = chunk && chunk.entryModule && chunk.entryModule.error;
if (e) throw e;

/* If any of dependency modules failed to build, throw the first found
* error that caused it. */
chunk._modules.forEach((m) => {
if (m.error) throw m.error;
});

/* Otherwise throw an error with the error message passed in, or with
* the fallback error message. */
throw new Error(typeof error === 'string' ? error : 'chunk is not an instance of Chunk');
}

return true;
Expand Down