UNPKG

1.01 kBJavaScriptView Raw
1"use strict";
2
3const WebpackError = require("./WebpackError");
4const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;
5
6/**
7 * @param {string=} method method name
8 * @returns {string} message
9 */
10function createMessage(method) {
11 return `Abstract method${method ? " " + method : ""}. Must be overridden.`;
12}
13
14/**
15 * @constructor
16 */
17function Message() {
18 this.stack = undefined;
19 Error.captureStackTrace(this);
20 /** @type {RegExpMatchArray} */
21 const match = this.stack.split("\n")[3].match(CURRENT_METHOD_REGEXP);
22
23 this.message = match && match[1] ? createMessage(match[1]) : createMessage();
24}
25
26/**
27 * Error for abstract method
28 * @example
29 * class FooClass {
30 * abstractMethod() {
31 * throw new AbstractMethodError(); // error message: Abstract method FooClass.abstractMethod. Must be overriden.
32 * }
33 * }
34 *
35 */
36class AbstractMethodError extends WebpackError {
37 constructor() {
38 super(new Message().message);
39 this.name = "AbstractMethodError";
40 }
41}
42
43module.exports = AbstractMethodError;