UNPKG

@averagehelper/corde

Version:

A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)

45 lines (44 loc) 2.08 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initErrorHandlers = void 0; const chalk_1 = __importDefault(require("chalk")); const common_1 = require("./common"); function initErrorHandlers() { process.on("uncaughtException", (err) => __awaiter(this, void 0, void 0, function* () { yield printErrorAndExit(err); })); process.on("unhandledRejection", (err) => __awaiter(this, void 0, void 0, function* () { yield printErrorAndExit(err); })); process.on("uncaughtExceptionMonitor", (err) => __awaiter(this, void 0, void 0, function* () { yield printErrorAndExit(err); })); } exports.initErrorHandlers = initErrorHandlers; function printErrorAndExit(error) { return __awaiter(this, void 0, void 0, function* () { console.log(error.stack); console.log(`${chalk_1.default.red("error")} Command failed with exit code 1`); if (common_1.runtime.isBotLoggedIn()) { common_1.runtime.logoffBot(); } if (common_1.testCollector.afterAllFunctions) { yield common_1.testCollector.afterAllFunctions.executeAsync(); } if (process.env.ENV !== "TEST") { process.exit(1); } }); }