"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleError = exports.HumanError = exports.ServerlessError = exports.InitError = exports.ConfigGetError = exports.ConfigError = exports.ConfigDeleteError = exports.CommandError = void 0;
/** @format */
var common_1 = require("../utils/common");
var handler_set_config_1 = require("../utils/handler-set-config");
var core_1 = __importDefault(require("../utils/core"));
var colors = core_1.default.colors, report = core_1.default.report, getMAC = core_1.default.getMAC;
var command_error_1 = require("./command-error");
Object.defineProperty(exports, "CommandError", { enumerable: true, get: function () { return command_error_1.CommandError; } });
var config_delete_error_1 = require("./config-delete-error");
Object.defineProperty(exports, "ConfigDeleteError", { enumerable: true, get: function () { return config_delete_error_1.ConfigDeleteError; } });
var config_error_1 = require("./config-error");
Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return config_error_1.ConfigError; } });
var config_get_error_1 = require("./config-get-error");
Object.defineProperty(exports, "ConfigGetError", { enumerable: true, get: function () { return config_get_error_1.ConfigGetError; } });
var init_error_1 = require("./init-error");
Object.defineProperty(exports, "InitError", { enumerable: true, get: function () { return init_error_1.InitError; } });
var serverless_error_1 = require("./serverless-error");
Object.defineProperty(exports, "ServerlessError", { enumerable: true, get: function () { return serverless_error_1.ServerlessError; } });
var human_error_1 = require("./human-error");
Object.defineProperty(exports, "HumanError", { enumerable: true, get: function () { return human_error_1.HumanError; } });
var pid = getMAC().replace(/:/g, '');
function underline(prefix, link) {
    return "" + colors.gray(prefix) + colors.gray.underline(link);
}
function handleError(error, prefix, exit) {
    if (prefix === void 0) { prefix = 'Message:'; }
    if (exit === void 0) { exit = true; }
    var traceId = "" + pid + Date.now();
    console.log((0, common_1.red)("\u2716 " + prefix + "\n"));
    var analysis = (0, handler_set_config_1.getConfig)('analysis');
    if (analysis !== 'disable') {
        console.log(colors.gray("TraceId:     " + traceId));
    }
    console.log(colors.gray("Environment: " + (0, common_1.getVersion)()));
    console.log(underline('Documents:   ', 'https://www.serverless-devs.com'));
    console.log(underline('Discussions: ', 'https://github.com/Serverless-Devs/Serverless-Devs/discussions'));
    console.log(underline('Issues:      ', 'https://github.com/Serverless-Devs/Serverless-Devs/issues\n'));
    console.log((0, common_1.bgRed)('ERROR:') + "\n" + error + "\n");
    if (analysis !== 'disable') {
        console.log(colors.gray("Please copy traceId: " + traceId + " and join Dingding group: 33947367 for consultation."));
    }
    console.log(colors.gray("You can run 's clean --cache' to prune Serverless devs."));
    console.log(colors.gray("And run again with the '--debug' option or 's -h' to get more logs.\n"));
    report({
        type: 'jsError',
        content: error.stack,
        traceId: traceId,
    }).then(function () { return exit && process.exit(1); });
}
exports.handleError = handleError;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZXJyb3IvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsY0FBYztBQUNkLDBDQUF5RDtBQUN6RCxrRUFBd0Q7QUFDeEQsdURBQWlDO0FBQ3pCLElBQUEsTUFBTSxHQUFxQixjQUFJLE9BQXpCLEVBQUUsTUFBTSxHQUFhLGNBQUksT0FBakIsRUFBRSxNQUFNLEdBQUssY0FBSSxPQUFULENBQVU7QUFDeEMsaURBQStDO0FBQXRDLDZHQUFBLFlBQVksT0FBQTtBQUNyQiw2REFBMEQ7QUFBakQsd0hBQUEsaUJBQWlCLE9BQUE7QUFDMUIsK0NBQTZDO0FBQXBDLDJHQUFBLFdBQVcsT0FBQTtBQUNwQix1REFBb0Q7QUFBM0Msa0hBQUEsY0FBYyxPQUFBO0FBQ3ZCLDJDQUF5QztBQUFoQyx1R0FBQSxTQUFTLE9BQUE7QUFDbEIsdURBQXFEO0FBQTVDLG1IQUFBLGVBQWUsT0FBQTtBQUN4Qiw2Q0FBMkM7QUFBbEMseUdBQUEsVUFBVSx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