|
| 1 | +/* |
| 2 | + MIT License http://www.opensource.org/licenses/mit-license.php |
| 3 | + Author Alexander Akait @alexander-akait |
| 4 | +*/ |
| 5 | + |
| 6 | +"use strict"; |
| 7 | + |
| 8 | +const PathVariableError = require("./PathVariableError"); |
| 9 | +const WebpackError = require("./WebpackError"); |
| 10 | +const deriveStackFromNestedError = require("./deriveStackFromNestedError"); |
| 11 | + |
| 12 | +/** @import RuntimeModule from "../runtime/RuntimeModule" */ |
| 13 | + |
| 14 | +/** |
| 15 | + * Names the runtime module that failed and, for a placeholder that only the |
| 16 | + * hashing pass lacks a value for, what to ask instead. |
| 17 | + * @param {RuntimeModule} module the runtime module whose `generate()` threw |
| 18 | + * @param {Error} error the error it threw |
| 19 | + * @returns {string} the message |
| 20 | + */ |
| 21 | +const buildMessage = (module, error) => { |
| 22 | + const message = `Generating the runtime module ${module.identifier()} (${ |
| 23 | + module.constructor.name |
| 24 | + }) for hashing failed: ${error.message}`; |
| 25 | + if (!(error instanceof PathVariableError)) return message; |
| 26 | + return `${message} |
| 27 | +A runtime module is generated to be hashed, before the chunk it belongs to has a hash, so ${error.variable} has no value there. Where the path from the chunk's own asset back to the output root is what is needed, ask compilation.runtimeTemplate.chunkRootOutputDir(chunk, enforceRelative), which neutralizes the hash placeholders first.`; |
| 28 | +}; |
| 29 | + |
| 30 | +class RuntimeModuleGenerationError extends WebpackError { |
| 31 | + /** |
| 32 | + * Creates an instance of RuntimeModuleGenerationError. |
| 33 | + * @param {RuntimeModule} module the runtime module whose `generate()` threw |
| 34 | + * @param {Error} error the error it threw |
| 35 | + */ |
| 36 | + constructor(module, error) { |
| 37 | + super(buildMessage(module, error)); |
| 38 | + |
| 39 | + /** @type {string} */ |
| 40 | + this.name = "RuntimeModuleGenerationError"; |
| 41 | + /** @type {Error} */ |
| 42 | + this.error = error; |
| 43 | + /** @type {RuntimeModule} */ |
| 44 | + this.module = module; |
| 45 | + |
| 46 | + deriveStackFromNestedError(this, error); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +/** @type {typeof RuntimeModuleGenerationError} */ |
| 51 | +module.exports = RuntimeModuleGenerationError; |
0 commit comments