time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

error.js (1226B)


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