3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Only tolerate recent plugin errors (not any errors)

This commit is contained in:
Dragory 2019-01-15 01:05:12 +02:00
parent 04618c4191
commit 7c39454a9d

View file

@ -4,22 +4,33 @@ import yaml from "js-yaml";
import _fs from "fs";
const fs = _fs.promises;
import {Knub, logger, PluginError} from "knub";
import { SimpleError } from "./SimpleError";
require("dotenv").config();
let recentErrors = 0;
let recentPluginErrors = 0;
const RECENT_ERROR_EXIT_THRESHOLD = 5;
setInterval(() => (recentErrors = Math.max(0, recentErrors - 1)), 2500);
setInterval(() => (recentPluginErrors = Math.max(0, recentPluginErrors - 1)), 2500);
process.on("unhandledRejection", (reason, p) => {
console.error(reason);
if (++recentErrors >= RECENT_ERROR_EXIT_THRESHOLD) process.exit(1);
if (reason instanceof PluginError) {
if (++recentPluginErrors >= RECENT_ERROR_EXIT_THRESHOLD) process.exit(1);
} else {
process.exit(1);
}
});
process.on("uncaughtException", err => {
console.error(err);
if (++recentErrors >= RECENT_ERROR_EXIT_THRESHOLD) process.exit(1);
if (err instanceof PluginError) {
if (++recentPluginErrors >= RECENT_ERROR_EXIT_THRESHOLD) process.exit(1);
} else {
process.exit(1);
}
});
// Verify required Node.js version
@ -37,7 +48,6 @@ import moment from "moment-timezone";
moment.tz.setDefault("UTC");
import { Client } from "eris";
import { Knub, logger } from "knub";
import { connect } from "./data/db";
// Global plugins