errors.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. class ERR_INVALID_ARG_TYPE extends TypeError {
  3. constructor(name, expected, actual) {
  4. super(`${name} must be ${expected} got ${actual}`);
  5. this.code = 'ERR_INVALID_ARG_TYPE';
  6. }
  7. }
  8. class ERR_INVALID_ARG_VALUE extends TypeError {
  9. constructor(arg1, arg2, expected) {
  10. super(`The property ${arg1} ${expected}. Received '${arg2}'`);
  11. this.code = 'ERR_INVALID_ARG_VALUE';
  12. }
  13. }
  14. class ERR_PARSE_ARGS_INVALID_OPTION_VALUE extends Error {
  15. constructor(message) {
  16. super(message);
  17. this.code = 'ERR_PARSE_ARGS_INVALID_OPTION_VALUE';
  18. }
  19. }
  20. class ERR_PARSE_ARGS_UNKNOWN_OPTION extends Error {
  21. constructor(option, allowPositionals) {
  22. 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)}` : '';
  23. super(`Unknown option '${option}'${suggestDashDash}`);
  24. this.code = 'ERR_PARSE_ARGS_UNKNOWN_OPTION';
  25. }
  26. }
  27. class ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL extends Error {
  28. constructor(positional) {
  29. super(`Unexpected argument '${positional}'. This command does not take positional arguments`);
  30. this.code = 'ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL';
  31. }
  32. }
  33. module.exports = {
  34. codes: {
  35. ERR_INVALID_ARG_TYPE,
  36. ERR_INVALID_ARG_VALUE,
  37. ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
  38. ERR_PARSE_ARGS_UNKNOWN_OPTION,
  39. ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
  40. }
  41. };