@boostercloud/cli
Version:
CLI of the Booster Framework, the next level of abstraction for cloud-native applications
26 lines (25 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unknownToError = exports.guardError = void 0;
exports.wrapExecError = wrapExecError;
const brand_1 = require("./brand");
const effect_1 = require("@boostercloud/framework-types/dist/effect");
/**
* Builds an error extracting its message from the "stdout" and "stderr" properties if present
* @param e
* @param prefix
*/
function wrapExecError(e, prefix) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { stdout, stderr } = e;
return new Error(brand_1.default.dangerize(prefix) + '\n' + stdout + stderr);
}
const guardError = (prefix) => (0, effect_1.orDieWith)((err) => {
return new Error(brand_1.default.dangerize(`[${err.name}] ${prefix}:`) + '\n' + err.message);
});
exports.guardError = guardError;
/**
* Converts an unknown value to an Error. If it's not an error already, it will be stringified.
*/
const unknownToError = (reason) => reason instanceof Error ? reason : new Error(JSON.stringify(reason));
exports.unknownToError = unknownToError;