error.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * CommanderError class
  3. * @class
  4. */
  5. class CommanderError extends Error {
  6. /**
  7. * Constructs the CommanderError class
  8. * @param {number} exitCode suggested exit code which could be used with process.exit
  9. * @param {string} code an id string representing the error
  10. * @param {string} message human-readable description of the error
  11. * @constructor
  12. */
  13. constructor(exitCode, code, message) {
  14. super(message);
  15. // properly capture stack trace in Node.js
  16. Error.captureStackTrace(this, this.constructor);
  17. this.name = this.constructor.name;
  18. this.code = code;
  19. this.exitCode = exitCode;
  20. this.nestedError = undefined;
  21. }
  22. }
  23. /**
  24. * InvalidArgumentError class
  25. * @class
  26. */
  27. class InvalidArgumentError extends CommanderError {
  28. /**
  29. * Constructs the InvalidArgumentError class
  30. * @param {string} [message] explanation of why argument is invalid
  31. * @constructor
  32. */
  33. constructor(message) {
  34. super(1, 'commander.invalidArgument', message);
  35. // properly capture stack trace in Node.js
  36. Error.captureStackTrace(this, this.constructor);
  37. this.name = this.constructor.name;
  38. }
  39. }
  40. exports.CommanderError = CommanderError;
  41. exports.InvalidArgumentError = InvalidArgumentError;