"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.failWrapper = failWrapper;
const chalk_1 = __importDefault(require("chalk"));
const loggingProvider_1 = require("../providers/logging/loggingProvider");
function failWrapper(func, exitCodeOnError = 1) {
    return (parsed) => func(parsed).catch((error) => {
        loggingProvider_1.logger.error(chalk_1.default.red.bold(error?.message ?? 'An unexpected error occurred'));
        loggingProvider_1.logger.error(error.stack);
        if (exitCodeOnError) {
            process.exitCode = exitCodeOnError;
        }
    });
}
