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 collections = require("../utils/collections.js");
|
||||
const parseCommand = require("../utils/parseCommand.js");
|
||||
const { clean } = require("../utils/misc.js");
|
||||
|
||||
// run when someone sends a 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({
|
||||
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), [{
|
||||
file: `Message: ${error}\n\nStack Trace: ${error.stack}`,
|
||||
file: `Message: ${await clean(error)}\n\nStack Trace: ${await clean(error.stack)}`,
|
||||
name: "error.txt"
|
||||
}]);
|
||||
} catch { /* silently ignore */ }
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const util = require("util");
|
||||
const fs = require("fs");
|
||||
|
||||
// random(array) to select a random entry in array
|
||||
exports.random = (array) => {
|
||||
|
@ -22,6 +23,11 @@ exports.clean = async (text) => {
|
|||
.replaceAll("@", `@${String.fromCharCode(8203)}`);
|
||||
|
||||
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)) {
|
||||
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 timeout = setTimeout(() => {
|
||||
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);
|
||||
this.start(object, num).catch(err => { // incredibly hacky code incoming
|
||||
clearTimeout(timeout);
|
||||
if (err instanceof Error) return reject(err);
|
||||
return err;
|
||||
}).then((data) => {
|
||||
this.start(object, num).then((data) => {
|
||||
clearTimeout(timeout);
|
||||
if (!data.event) reject("Not connected to image server");
|
||||
data.event.once("image", (image, type) => {
|
||||
|
@ -256,7 +252,8 @@ class ImageWorker extends BaseServiceWorker {
|
|||
async handleCommand(data) {
|
||||
try {
|
||||
if (data.type === "run") {
|
||||
return await this.run(data.obj);
|
||||
const result = await this.run(data.obj);
|
||||
return result;
|
||||
} else if (data.type === "reload") {
|
||||
await this.disconnect();
|
||||
await this.repopulate();
|
||||
|
@ -274,7 +271,7 @@ class ImageWorker extends BaseServiceWorker {
|
|||
return await this.getRunning();
|
||||
}
|
||||
} catch (err) {
|
||||
return { err: err.message };
|
||||
return { err: typeof err === "string" ? err : err.message };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue