Skip to content

Commit 0006574

Browse files
committed
log a warning when serialization fails
1 parent 9debdd3 commit 0006574

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/cache/FileCachePlugin.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const path = require("path");
99
const createHash = require("../util/createHash");
1010
const makeSerializable = require("../util/makeSerializable");
11-
const { serializer } = require("../util/serialization");
11+
const { serializer, NOT_SERIALIZABLE } = require("../util/serialization");
1212

1313
/** @typedef {import("webpack-sources").Source} Source */
1414
/** @typedef {import("../../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
@@ -23,6 +23,7 @@ class Pack {
2323
this.unserializable = new Set();
2424
this.used = new Set();
2525
this.invalid = false;
26+
this.log = 0;
2627
}
2728

2829
get(identifier) {
@@ -48,6 +49,10 @@ class Pack {
4849
}
4950
}
5051

52+
setLogLevel(log) {
53+
this.log = log;
54+
}
55+
5156
_updateLastAccess() {
5257
const now = Date.now();
5358
for (const identifier of this.used) {
@@ -65,6 +70,13 @@ class Pack {
6570
write(identifier);
6671
write(data);
6772
} catch (err) {
73+
if (this.log >= 1 && err !== NOT_SERIALIZABLE) {
74+
console.warn(
75+
`Caching failed for ${identifier}: ${
76+
this.log >= 4 ? err.stack : err
77+
}\nWe will not try to cache this entry again until the cache file is deleted.`
78+
);
79+
}
6880
rollback(s);
6981
this.unserializable.add(identifier);
7082
continue;
@@ -294,6 +306,7 @@ class FileCachePlugin {
294306
console.warn(`Storing pack...`);
295307
}
296308
pack.collectGarbage(1000 * 60 * 60 * 24 * 2);
309+
pack.setLogLevel(log);
297310
// You might think this breaks all access to the existing pack
298311
// which are still referenced, but serializing the pack memorizes
299312
// all data in the pack and makes it no longer need the backing file

lib/serialization/ObjectMiddleware.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,4 @@ class ObjectMiddleware extends SerializerMiddleware {
482482
}
483483

484484
module.exports = ObjectMiddleware;
485+
module.exports.NOT_SERIALIZABLE = NOT_SERIALIZABLE;

lib/util/serialization.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const { register, registerLoader, registerNotSerializable } = ObjectMiddleware;
1818
exports.register = register;
1919
exports.registerLoader = registerLoader;
2020
exports.registerNotSerializable = registerNotSerializable;
21+
exports.NOT_SERIALIZABLE = ObjectMiddleware.NOT_SERIALIZABLE;
2122
exports.serializer = new Serializer(
2223
[new ObjectMiddleware(), new BinaryMiddleware(), new FileMiddleware()],
2324
{

0 commit comments

Comments
 (0)