From 702bf39df4627377c6549808c7772982966248cf Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Sat, 27 Jan 2024 23:08:30 +1100 Subject: [PATCH] Notify over DM channel regarding I/O issues --- src/index.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index b4876b8..1667a56 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,13 +8,27 @@ import MPModule, {refreshTimerSecs} from './modules/MPModule.js'; import UsernameHelper from './helpers/UsernameHelper.js'; import {Punishment, RawGatewayPacket, RawMessageDelete, RawMessageUpdate} from 'src/interfaces'; import {readFileSync} from 'node:fs'; +import {execSync} from 'node:child_process'; export const disabledChannels = ['548032776830582794', '541677709487505408', '949380187668242483']; // Error handler function _(error:Error, type:string) { if (JSON.parse(readFileSync('src/errorBlocklist.json', 'utf8')).includes(error.message)) return; console.error(error); - (client.channels.resolve(client.config.dcServer.channels.errors) as Discord.TextChannel | null)?.send({embeds: [new client.embed().setColor('#560000').setTitle('Error caught!').setFooter({text: 'Error type: ' + type}).setDescription(`**Error:**\n\`\`\`${error.message}\`\`\`**Stack:**\n\`\`\`${`${UsernameHelper(error.stack)}`.slice(0, 2500)}\`\`\``)]}) + (client.channels.resolve(client.config.dcServer.channels.errors) as Discord.TextChannel | null)?.send({embeds: [new client.embed().setColor('#560000').setTitle('Error caught!').setFooter({text: `Error type: ${type}`}).setDescription(`**Error:**\n\`\`\`${error.message}\`\`\`**Stack:**\n\`\`\`${`${UsernameHelper(error.stack)}`.slice(0, 2500)}\`\`\``)]}) + + if (error.message.includes('could not fdatasync file')) { + client.users.createDM(client.config.whitelist[1]).then(u=>u.send({ + embeds: [new client.embed() + .setColor(client.config.embedColorYellow) + .setTitle('Database error') + .setDescription('I couldn\'t write to the database due to filesystem issues, shutting down...') + .setFields({name: 'Error message', value: `\`\`\`${error.message}\`\`\``}) + .setFooter({text: `Error type: ${type}`}) + ] + })); + setTimeout(()=>execSync('pm2 stop 0', {shell: 'bash'}), 5500); + } } process.on('unhandledRejection', (error: Error)=>_(error, 'unhandledRejection')); process.on('uncaughtException', (error: Error)=>_(error, 'uncaughtException'));