Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Uncaught exception from renderers
  • Loading branch information
chuckdumont committed Sep 21, 2018
1 parent 31d735c commit f8877e0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
38 changes: 21 additions & 17 deletions lib/Compilation.js
Expand Up @@ -2254,24 +2254,28 @@ class Compilation extends Tapable {
for (let i = 0; i < chunks.length; i++) {
const chunk = chunks[i];
const chunkHash = createHash(hashFunction);
if (outputOptions.hashSalt) {
chunkHash.update(outputOptions.hashSalt);
try {
if (outputOptions.hashSalt) {
chunkHash.update(outputOptions.hashSalt);
}
chunk.updateHash(chunkHash);
const template = chunk.hasRuntime()
? this.mainTemplate
: this.chunkTemplate;
template.updateHashForChunk(
chunkHash,
chunk,
this.moduleTemplates.javascript,
this.dependencyTemplates
);
this.hooks.chunkHash.call(chunk, chunkHash);
chunk.hash = chunkHash.digest(hashDigest);
hash.update(chunk.hash);
chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
this.hooks.contentHash.call(chunk);
} catch (err) {
this.errors.push(new ChunkRenderError(chunk, "", err));
}
chunk.updateHash(chunkHash);
const template = chunk.hasRuntime()
? this.mainTemplate
: this.chunkTemplate;
template.updateHashForChunk(
chunkHash,
chunk,
this.moduleTemplates.javascript,
this.dependencyTemplates
);
this.hooks.chunkHash.call(chunk, chunkHash);
chunk.hash = chunkHash.digest(hashDigest);
hash.update(chunk.hash);
chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
this.hooks.contentHash.call(chunk);
}
this.fullHash = hash.digest(hashDigest);
this.hash = this.fullHash.substr(0, hashDigestLength);
Expand Down
4 changes: 4 additions & 0 deletions test/configCases/errors/exception-in-chunk-renderer/errors.js
@@ -0,0 +1,4 @@
module.exports = [
[/Test exception/],
[/Test exception/]
];
3 changes: 3 additions & 0 deletions test/configCases/errors/exception-in-chunk-renderer/index.js
@@ -0,0 +1,3 @@
it("should not crash when renderer throws exception", function(done) {
done();
});
@@ -0,0 +1,16 @@
class ThrowsExceptionInRender {
apply(compiler) {
compiler.hooks.compilation.tap("ThrowsException", compilation => {
compilation.mainTemplate.hooks.requireExtensions.tap(
"ThrowsException",
() => {
throw new Error("Test exception");
}
);
});
}
}

module.exports = {
plugins: [new ThrowsExceptionInRender()]
};

0 comments on commit f8877e0

Please sign in to comment.