error.js 1.1 KB

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