mirror of https://github.com/webpack/webpack.git
fix: serialize `HookWebpackError` (#20169)
This commit is contained in:
parent
1b5084e3c4
commit
9abcf3fa8f
|
|
@ -6,6 +6,10 @@
|
|||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
const makeSerializable = require("./util/makeSerializable");
|
||||
|
||||
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
||||
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
|
||||
/**
|
||||
* @template T
|
||||
|
|
@ -22,18 +26,43 @@ class HookWebpackError extends WebpackError {
|
|||
* @param {string} hook name of hook
|
||||
*/
|
||||
constructor(error, hook) {
|
||||
super(error.message);
|
||||
super(error ? error.message : undefined, error ? { cause: error } : {});
|
||||
|
||||
this.name = "HookWebpackError";
|
||||
this.hook = hook;
|
||||
this.error = error;
|
||||
this.name = "HookWebpackError";
|
||||
this.hideStack = true;
|
||||
this.details = `caused by plugins in ${hook}\n${error.stack}`;
|
||||
this.stack += `\n-- inner error --\n${error ? error.stack : ""}`;
|
||||
this.details = `caused by plugins in ${hook}\n${error ? error.stack : ""}`;
|
||||
}
|
||||
|
||||
this.stack += `\n-- inner error --\n${error.stack}`;
|
||||
/**
|
||||
* @param {ObjectSerializerContext} context context
|
||||
*/
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
|
||||
write(this.error);
|
||||
write(this.hook);
|
||||
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectDeserializerContext} context context
|
||||
*/
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
|
||||
this.error = read();
|
||||
this.hook = read();
|
||||
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
makeSerializable(HookWebpackError, "webpack/lib/HookWebpackError");
|
||||
|
||||
module.exports = HookWebpackError;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = [[/Module build failed/]];
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import value from "./my-errored-module.js"
|
||||
|
||||
it("should work and cache", function(done) {
|
||||
done();
|
||||
});
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = (options) => {
|
||||
if (options.cache && options.cache.type === "filesystem") {
|
||||
return [/Pack got invalid because of write to/];
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
const HookWebpackError = require('../../../../lib/HookWebpackError.js');
|
||||
|
||||
/** @type {import("../../../../").LoaderDefinition} */
|
||||
module.exports = function loader() {
|
||||
const callback = this.async();
|
||||
|
||||
callback(new HookWebpackError(new Error("Error: test"), "hookName"));
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /my-errored-module\.js$/i,
|
||||
use: [
|
||||
{
|
||||
loader: require.resolve("./loader.js")
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue