1.17 kBJavaScriptView Raw
1/**
2 * CommanderError class
3 */
4class 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/**
23 * InvalidArgumentError class
24 */
25class InvalidArgumentError extends CommanderError {
26 /**
27 * Constructs the InvalidArgumentError class
28 * @param {string} [message] explanation of why argument is invalid
29 */
30 constructor(message) {
31 super(1, 'commander.invalidArgument', message);
32 // properly capture stack trace in Node.js
33 Error.captureStackTrace(this, this.constructor);
34 this.name = this.constructor.name;
35 }
36}
37
38exports.CommanderError = CommanderError;
39exports.InvalidArgumentError = InvalidArgumentError;