| 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Jarid Margolin @jaridmargolin
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | const inspect = require("util").inspect.custom;
|
|---|
| 9 | const makeSerializable = require("../util/makeSerializable");
|
|---|
| 10 |
|
|---|
| 11 | /** @typedef {import("../Chunk")} Chunk */
|
|---|
| 12 | /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
|---|
| 13 | /** @typedef {import("../Module")} Module */
|
|---|
| 14 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|---|
| 15 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|---|
| 16 |
|
|---|
| 17 | class WebpackError extends Error {
|
|---|
| 18 | /**
|
|---|
| 19 | * Creates an instance of WebpackError.
|
|---|
| 20 | * @param {string=} message error message
|
|---|
| 21 | * @param {{ cause?: unknown }} options error options
|
|---|
| 22 | */
|
|---|
| 23 | constructor(message, options = {}) {
|
|---|
| 24 | super(message, options);
|
|---|
| 25 |
|
|---|
| 26 | /** @type {string=} */
|
|---|
| 27 | this.details = undefined;
|
|---|
| 28 | /** @type {(Module | null)=} */
|
|---|
| 29 | this.module = undefined;
|
|---|
| 30 | /** @type {DependencyLocation=} */
|
|---|
| 31 | this.loc = undefined;
|
|---|
| 32 | /** @type {boolean=} */
|
|---|
| 33 | this.hideStack = undefined;
|
|---|
| 34 | /** @type {Chunk=} */
|
|---|
| 35 | this.chunk = undefined;
|
|---|
| 36 | /** @type {string=} */
|
|---|
| 37 | this.file = undefined;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | /**
|
|---|
| 41 | * Returns inspect message.
|
|---|
| 42 | * @returns {string} inspect message
|
|---|
| 43 | */
|
|---|
| 44 | [inspect]() {
|
|---|
| 45 | return (
|
|---|
| 46 | this.stack +
|
|---|
| 47 | (this.details ? `\n${this.details}` : "") +
|
|---|
| 48 | (this.cause ? `\n${this.cause}` : "")
|
|---|
| 49 | );
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | /**
|
|---|
| 53 | * Serializes this instance into the provided serializer context.
|
|---|
| 54 | * @param {ObjectSerializerContext} context context
|
|---|
| 55 | */
|
|---|
| 56 | serialize({ write }) {
|
|---|
| 57 | write(this.name);
|
|---|
| 58 | write(this.message);
|
|---|
| 59 | write(this.stack);
|
|---|
| 60 | write(this.cause);
|
|---|
| 61 | write(this.details);
|
|---|
| 62 | write(this.loc);
|
|---|
| 63 | write(this.hideStack);
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | /**
|
|---|
| 67 | * Restores this instance from the provided deserializer context.
|
|---|
| 68 | * @param {ObjectDeserializerContext} context context
|
|---|
| 69 | */
|
|---|
| 70 | deserialize({ read }) {
|
|---|
| 71 | this.name = read();
|
|---|
| 72 | this.message = read();
|
|---|
| 73 | this.stack = read();
|
|---|
| 74 | this.cause = read();
|
|---|
| 75 | this.details = read();
|
|---|
| 76 | this.loc = read();
|
|---|
| 77 | this.hideStack = read();
|
|---|
| 78 | }
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | makeSerializable(WebpackError, "webpack/lib/errors/WebpackError");
|
|---|
| 82 |
|
|---|
| 83 | /** @type {typeof WebpackError} */
|
|---|
| 84 | module.exports = WebpackError;
|
|---|