From 1f0b700e8213da143b090c84104874c98e5c49b8 Mon Sep 17 00:00:00 2001 From: hgw Date: Mon, 2 Oct 2023 02:11:26 +0000 Subject: [PATCH] Add somewhat decent error handling finally --- bot.js | 13 ++++++++++--- config/example.default.json | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bot.js b/bot.js index 7817a43..136314f 100644 --- a/bot.js +++ b/bot.js @@ -134,11 +134,18 @@ fs.open('./config/usersettings.json','r',function(err, fd){ if(err) { console.log(err); } - console.log("usersettings.json did not exist, it has been created"); + console.log("[main.setup] usersettings.json did not exist, it has been created"); }); fs.writeFileSync('./config/usersettings.json', "\{\n\}") } else { - console.log("usersettings.json exists, continuing"); + console.log("[main] usersettings.json exists, continuing"); } }); -console.log('[main.irc] Connecting to '+config.irc.server+'/'+config.irc.port+' as '+config.irc.nickname); \ No newline at end of file +console.log('[main.irc] Connecting to '+config.irc.server+'/'+config.irc.port+' as '+config.irc.nickname); + +process.on('uncaughtException', function (err) { + console.error(err); + if (config.errorhandling.log_errors_to_irc == 'true') { + bot.say(config.errorhandling.error_channel, errorMsg+" "+err.stack.split('\n',1).join(" ")) + } +}); \ No newline at end of file diff --git a/config/example.default.json b/config/example.default.json index ca766dd..4f6bd62 100644 --- a/config/example.default.json +++ b/config/example.default.json @@ -8,12 +8,17 @@ ], "nickname": "mercury", "username": "mercury", - "realname": "git.supernets.org/hogwart7/mercury", + "realname": "git.supernets.org/hgw/mercury", "autorejoin": "true", "floodprotection": "false", "floodprotectiondelay": "0", "prefix": "m!" }, + "errorhandling": { + "error_logging": "true", + "error_channel": "#CHANNELTOSENDERRORSTO", + "error_channel_pass": "" + }, "colours": { "date": "11", "brackets": "15",