Skip to content

Commit

Permalink
fix: not writing to error.log
Browse files Browse the repository at this point in the history
  • Loading branch information
Max committed Dec 5, 2021
1 parent 6133bc9 commit 9f2f269
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand All @@ -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();
Expand Down

0 comments on commit 9f2f269

Please sign in to comment.