This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.

34 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-04-02 02:24:13 +03:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.inlineString = exports.CLIError = void 0;
/**
* A custom Error that creates a single-lined message to match current styling inside CLI.
* Uses original stack trace when `originalError` is passed or erase the stack if it's not defined.
*/
class CLIError extends Error {
constructor(msg, originalError) {
super(inlineString(msg));
if (originalError) {
this.stack = typeof originalError === 'string' ? originalError : (originalError.stack || '').split('\n').slice(0, 2).join('\n');
} else {
// When the "originalError" is not passed, it means that we know exactly
// what went wrong and provide means to fix it. In such cases showing the
// stack is an unnecessary clutter to the CLI output, hence removing it.
delete this.stack;
}
}
}
exports.CLIError = CLIError;
const inlineString = str => str.replace(/(\s{2,})/gm, ' ').trim();
exports.inlineString = inlineString;
//# sourceMappingURL=errors.js.map