From 9f2f2695e13042e4afb26fc9e00eddfa76ce5e50 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 5 Dec 2021 11:22:17 +0800 Subject: [PATCH] fix: not writing to error.log --- main.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 833fc3d4..5000c2db 100644 --- a/main.js +++ b/main.js @@ -194,7 +194,7 @@ bot.on('guildDelete', guild => { bot.login(token); let inprg = false; -async function shuttingDown(err) { +async function shuttingDown(eventType, err) { if (inprg) return; inprg = true; console.log('[Warden] Shutting down...'); @@ -215,9 +215,14 @@ async function shuttingDown(err) { bot.music.destroyPlayer(player.guildId); } } - if (err) { + if (['uncaughtException', 'unhandledRejection'].includes(eventType) && err) { console.log('[Warden] Logging error to error.log.'); - await fsPromises.writeFile('error.log', err); + try { + await fsPromises.writeFile('error.log', err.toString()); + } + catch (e) { + console.error(`[Warden] Encountered error while writing to error.log:\n${e}`); + } } bot.destroy(); process.exit();