You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1008 B

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