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