Improved error handling
This commit is contained in:
parent
7b07f82285
commit
77ca0fd344
3 changed files with 13 additions and 9 deletions
|
@ -3,6 +3,7 @@ const database = require("../utils/database.js");
|
||||||
const logger = require("../utils/logger.js");
|
const logger = require("../utils/logger.js");
|
||||||
const collections = require("../utils/collections.js");
|
const collections = require("../utils/collections.js");
|
||||||
const parseCommand = require("../utils/parseCommand.js");
|
const parseCommand = require("../utils/parseCommand.js");
|
||||||
|
const { clean } = require("../utils/misc.js");
|
||||||
|
|
||||||
// run when someone sends a message
|
// run when someone sends a message
|
||||||
module.exports = async (client, cluster, worker, ipc, message) => {
|
module.exports = async (client, cluster, worker, ipc, message) => {
|
||||||
|
@ -141,7 +142,7 @@ module.exports = async (client, cluster, worker, ipc, message) => {
|
||||||
await client.createMessage(message.channel.id, Object.assign({
|
await client.createMessage(message.channel.id, Object.assign({
|
||||||
content: "Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>"
|
content: "Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>"
|
||||||
}, reference), [{
|
}, reference), [{
|
||||||
file: `Message: ${error}\n\nStack Trace: ${error.stack}`,
|
file: `Message: ${await clean(error)}\n\nStack Trace: ${await clean(error.stack)}`,
|
||||||
name: "error.txt"
|
name: "error.txt"
|
||||||
}]);
|
}]);
|
||||||
} catch { /* silently ignore */ }
|
} catch { /* silently ignore */ }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
// random(array) to select a random entry in array
|
// random(array) to select a random entry in array
|
||||||
exports.random = (array) => {
|
exports.random = (array) => {
|
||||||
|
@ -22,6 +23,11 @@ exports.clean = async (text) => {
|
||||||
.replaceAll("@", `@${String.fromCharCode(8203)}`);
|
.replaceAll("@", `@${String.fromCharCode(8203)}`);
|
||||||
|
|
||||||
const { parsed } = require("dotenv").config();
|
const { parsed } = require("dotenv").config();
|
||||||
|
const imageServers = JSON.parse(fs.readFileSync("./servers.json", { encoding: "utf8" })).image;
|
||||||
|
|
||||||
|
for (const server of imageServers) {
|
||||||
|
text = text.replaceAll(server, "<redacted>");
|
||||||
|
}
|
||||||
|
|
||||||
for (const env of Object.keys(parsed)) {
|
for (const env of Object.keys(parsed)) {
|
||||||
text = text.replaceAll(parsed[env], optionalReplace(parsed[env]));
|
text = text.replaceAll(parsed[env], optionalReplace(parsed[env]));
|
||||||
|
|
|
@ -213,13 +213,9 @@ class ImageWorker extends BaseServiceWorker {
|
||||||
const num = Math.floor(Math.random() * 100000).toString().slice(0, 5);
|
const num = Math.floor(Math.random() * 100000).toString().slice(0, 5);
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
if (this.jobs[num]) delete this.jobs[num];
|
if (this.jobs[num]) delete this.jobs[num];
|
||||||
reject("the image request timed out after 25 seconds. Try uploading your image elsewhere.");
|
reject("The image request timed out after 25 seconds. Try uploading your image elsewhere.");
|
||||||
}, 25000);
|
}, 25000);
|
||||||
this.start(object, num).catch(err => { // incredibly hacky code incoming
|
this.start(object, num).then((data) => {
|
||||||
clearTimeout(timeout);
|
|
||||||
if (err instanceof Error) return reject(err);
|
|
||||||
return err;
|
|
||||||
}).then((data) => {
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
if (!data.event) reject("Not connected to image server");
|
if (!data.event) reject("Not connected to image server");
|
||||||
data.event.once("image", (image, type) => {
|
data.event.once("image", (image, type) => {
|
||||||
|
@ -256,7 +252,8 @@ class ImageWorker extends BaseServiceWorker {
|
||||||
async handleCommand(data) {
|
async handleCommand(data) {
|
||||||
try {
|
try {
|
||||||
if (data.type === "run") {
|
if (data.type === "run") {
|
||||||
return await this.run(data.obj);
|
const result = await this.run(data.obj);
|
||||||
|
return result;
|
||||||
} else if (data.type === "reload") {
|
} else if (data.type === "reload") {
|
||||||
await this.disconnect();
|
await this.disconnect();
|
||||||
await this.repopulate();
|
await this.repopulate();
|
||||||
|
@ -274,7 +271,7 @@ class ImageWorker extends BaseServiceWorker {
|
||||||
return await this.getRunning();
|
return await this.getRunning();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { err: err.message };
|
return { err: typeof err === "string" ? err : err.message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue