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