• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3class ERR_INVALID_ARG_TYPE extends TypeError {
4  constructor(name, expected, actual) {
5    super(`${name} must be ${expected} got ${actual}`);
6    this.code = 'ERR_INVALID_ARG_TYPE';
7  }
8}
9
10class ERR_INVALID_ARG_VALUE extends TypeError {
11  constructor(arg1, arg2, expected) {
12    super(`The property ${arg1} ${expected}. Received '${arg2}'`);
13    this.code = 'ERR_INVALID_ARG_VALUE';
14  }
15}
16
17class ERR_PARSE_ARGS_INVALID_OPTION_VALUE extends Error {
18  constructor(message) {
19    super(message);
20    this.code = 'ERR_PARSE_ARGS_INVALID_OPTION_VALUE';
21  }
22}
23
24class ERR_PARSE_ARGS_UNKNOWN_OPTION extends Error {
25  constructor(option, allowPositionals) {
26    const suggestDashDash = allowPositionals ? `. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- ${JSON.stringify(option)}` : '';
27    super(`Unknown option '${option}'${suggestDashDash}`);
28    this.code = 'ERR_PARSE_ARGS_UNKNOWN_OPTION';
29  }
30}
31
32class ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL extends Error {
33  constructor(positional) {
34    super(`Unexpected argument '${positional}'. This command does not take positional arguments`);
35    this.code = 'ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL';
36  }
37}
38
39module.exports = {
40  codes: {
41    ERR_INVALID_ARG_TYPE,
42    ERR_INVALID_ARG_VALUE,
43    ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
44    ERR_PARSE_ARGS_UNKNOWN_OPTION,
45    ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
46  }
47};
48