errors.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.inlineString = exports.CLIError = void 0;
  6. /**
  7. * A custom Error that creates a single-lined message to match current styling inside CLI.
  8. * Uses original stack trace when `originalError` is passed or erase the stack if it's not defined.
  9. */
  10. class CLIError extends Error {
  11. constructor(msg, originalError) {
  12. super(inlineString(msg));
  13. if (originalError) {
  14. this.stack = typeof originalError === 'string' ? originalError : (originalError.stack || '').split('\n').slice(0, 2).join('\n');
  15. } else {
  16. // When the "originalError" is not passed, it means that we know exactly
  17. // what went wrong and provide means to fix it. In such cases showing the
  18. // stack is an unnecessary clutter to the CLI output, hence removing it.
  19. delete this.stack;
  20. }
  21. }
  22. }
  23. exports.CLIError = CLIError;
  24. const inlineString = str => str.replace(/(\s{2,})/gm, ' ').trim();
  25. exports.inlineString = inlineString;
  26. //# sourceMappingURL=errors.js.map