"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.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 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:'));
    console.log(error);
    console.log('');
    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 -all' to prune Serverless devs."));
    console.log(colors.gray("Run again with the '--debug' option or 's -h' to get more logs."));
    report({
        type: 'jsError',
        content: error.stack,
        traceId: traceId,
    }).then(function () { return exit && process.exit(-1); });
}
exports.handleError = handleError;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZXJyb3IvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsY0FBYztBQUNkLDBDQUF5RDtBQUN6RCxrRUFBd0Q7QUFDeEQsdURBQWlDO0FBQ3pCLElBQUEsTUFBTSxHQUFxQixjQUFJLE9BQXpCLEVBQUUsTUFBTSxHQUFhLGNBQUksT0FBakIsRUFBRSxNQUFNLEdBQUssY0FBSSxPQUFULENBQVU7QUFDeEMsaURBQStDO0FBQXRDLDZHQUFBLFlBQVksT0FBQTtBQUNyQiw2REFBMEQ7QUFBakQsd0hBQUEsaUJBQWlCLE9BQUE7QUFDMUIsK0NBQTZDO0FBQXBDLDJHQUFBLFdBQVcsT0FBQTtBQUNwQix1REFBb0Q7QUFBM0Msa0hBQUEsY0FBYyxPQUFBO0FBQ3ZCLDJDQUF5QztBQUFoQyx1R0FBQSxTQUFTLE9BQUE7QUFDbEIsdURBQXFEO0FBQTVDLG1IQUFBLGVBQWUsT0FBQTtBQUV4QixJQUFNLEdBQUcsR0FBRyxNQUFNLEVBQUUsQ0FBQyxPQUFPLENBQUMsSUFBSSxFQUFFLEVBQUUsQ0FBQyxDQUFDO0FBRXZDLFNBQVMsU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