webpack/lib/WebpackError.js

62 lines
1.3 KiB
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Jarid Margolin @jaridmargolin
*/
2018-07-30 23:08:51 +08:00
"use strict";
const inspect = require("util").inspect.custom;
2018-10-25 16:47:52 +08:00
const makeSerializable = require("./util/makeSerializable");
/** @typedef {import("./Chunk")} Chunk */
2018-07-14 03:30:55 +08:00
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("./Module")} Module */
2018-07-14 03:30:55 +08:00
class WebpackError extends Error {
/**
* Creates an instance of WebpackError.
* @param {string=} message error message
*/
constructor(message) {
super(message);
2018-04-08 08:44:27 +08:00
2018-04-12 00:44:28 +08:00
this.details = undefined;
/** @type {Module} */
this.module = undefined;
2018-07-14 03:30:55 +08:00
/** @type {DependencyLocation} */
this.loc = undefined;
2018-10-25 16:49:51 +08:00
/** @type {boolean} */
this.hideStack = undefined;
/** @type {Chunk} */
this.chunk = undefined;
/** @type {string} */
this.file = undefined;
}
[inspect]() {
return this.stack + (this.details ? `\n${this.details}` : "");
}
2018-10-25 16:47:52 +08:00
2018-10-25 16:49:51 +08:00
serialize({ write }) {
write(this.name);
write(this.message);
write(this.stack);
2018-10-25 16:47:52 +08:00
write(this.details);
write(this.loc);
2018-10-25 16:49:51 +08:00
write(this.hideStack);
2018-10-25 16:47:52 +08:00
}
2018-10-25 16:49:51 +08:00
deserialize({ read }) {
this.name = read();
this.message = read();
this.stack = read();
2018-10-25 16:47:52 +08:00
this.details = read();
this.loc = read();
2018-10-25 16:49:51 +08:00
this.hideStack = read();
2018-10-25 16:47:52 +08:00
}
}
2018-10-25 16:47:52 +08:00
makeSerializable(WebpackError, "webpack/lib/WebpackError");
module.exports = WebpackError;