Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Ivan Kopeykin @vankop
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const WebpackError = require("./WebpackError");
|
---|
| 9 | const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * @param {string=} method method name
|
---|
| 13 | * @returns {string} message
|
---|
| 14 | */
|
---|
| 15 | function createMessage(method) {
|
---|
| 16 | return `Abstract method${method ? " " + method : ""}. Must be overridden.`;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * @constructor
|
---|
| 21 | */
|
---|
| 22 | function Message() {
|
---|
| 23 | /** @type {string} */
|
---|
| 24 | this.stack = undefined;
|
---|
| 25 | Error.captureStackTrace(this);
|
---|
| 26 | /** @type {RegExpMatchArray} */
|
---|
| 27 | const match = this.stack.split("\n")[3].match(CURRENT_METHOD_REGEXP);
|
---|
| 28 |
|
---|
| 29 | this.message = match && match[1] ? createMessage(match[1]) : createMessage();
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | * Error for abstract method
|
---|
| 34 | * @example
|
---|
| 35 | * class FooClass {
|
---|
| 36 | * abstractMethod() {
|
---|
| 37 | * throw new AbstractMethodError(); // error message: Abstract method FooClass.abstractMethod. Must be overridden.
|
---|
| 38 | * }
|
---|
| 39 | * }
|
---|
| 40 | *
|
---|
| 41 | */
|
---|
| 42 | class AbstractMethodError extends WebpackError {
|
---|
| 43 | constructor() {
|
---|
| 44 | super(new Message().message);
|
---|
| 45 | this.name = "AbstractMethodError";
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | module.exports = AbstractMethodError;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.