Skip to content
Myr

error.js

This file

Path

lib/error.js

45 lines · 1.2 KiB · JavaScript

Last changed by

Refactor classes into files (#1522)John Geebefore adoption08245cc

History of this file

Take it

Refactor classes into files (#1522)John Geebefore adoption08245cc

lines 1–45why, one step back
1// @ts-check
23/**4 * CommanderError class5 * @class6 */7class CommanderError extends Error {8 /**9 * Constructs the CommanderError class10 * @param {number} exitCode suggested exit code which could be used with process.exit11 * @param {string} code an id string representing the error12 * @param {string} message human-readable description of the error13 * @constructor14 */15 constructor(exitCode, code, message) {16 super(message);17 // properly capture stack trace in Node.js18 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}2526/**27 * InvalidArgumentError class28 * @class29 */30class InvalidArgumentError extends CommanderError {31 /**32 * Constructs the InvalidArgumentError class33 * @param {string} [message] explanation of why argument is invalid34 * @constructor35 */36 constructor(message) {37 super(1, 'commander.invalidArgument', message);38 // properly capture stack trace in Node.js39 Error.captureStackTrace(this, this.constructor);40 this.name = this.constructor.name;41 }42}4344exports.CommanderError = CommanderError;45exports.InvalidArgumentError = InvalidArgumentError;