* Creates an instance of ModuleBuildError. * @param {string | ErrorWithHideStack} err error thrown * @param {{ from?: string | null }} info additional info
(err, { from = null } = {})
| 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 | // V8 prefixes `.stack` with "Name: message"; JSC and others emit |
| 36 | // frames only, which would drop the message. Lead with it then. |
| 37 | message += |
| 38 | typeof err.message === "string" && |
| 39 | err.message && |
| 40 | !stack.includes(err.message) |
| 41 | ? `${err.name ? `${err.name}: ` : ""}${err.message}` |
| 42 | : stack; |
| 43 | } else { |
| 44 | details = stack; |
| 45 | |
| 46 | message += |
| 47 | typeof err.message === "string" && err.message ? err.message : err; |
| 48 | } |
| 49 | } else if (typeof err.message === "string" && err.message) { |
| 50 | message += err.message; |
| 51 | } else { |
| 52 | message += String(err); |
| 53 | } |
| 54 | } else { |
| 55 | message += String(err); |
| 56 | } |
| 57 | |
| 58 | super(message); |
| 59 | |
| 60 | /** @type {string} */ |
| 61 | this.name = "ModuleBuildError"; |
| 62 | /** @type {string | undefined} */ |
| 63 | this.details = details; |
| 64 | /** @type {string | ErrorWithHideStack} */ |
| 65 | this.error = err; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Serializes this instance into the provided serializer context. |
nothing calls this directly
no test coverage detected