From 81217ece50f93f044e9f995951510afa2027e1b5 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 23 Dec 2012 02:25:58 +0000 Subject: [PATCH] Add a debug mode that shows the error and the top of the stack trace in the case of an error if activated. --- config.json.sample | 3 ++- modules/command/command.js | 10 +++++++++- run.js | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config.json.sample b/config.json.sample index 31c11f6..685eee6 100644 --- a/config.json.sample +++ b/config.json.sample @@ -13,5 +13,6 @@ }, "admins": [ "batman" ], "moduleNames": [ "ignore", "admin", "command", "dice", "js", "kick", "puns", "quotes", "spelling", "youare" ], - "language": "english" + "language": "english", + "debugMode": true } diff --git a/modules/command/command.js b/modules/command/command.js index 6342da2..ff530ff 100644 --- a/modules/command/command.js +++ b/modules/command/command.js @@ -79,7 +79,15 @@ var command = function(dbot) { } else { if(!isIgnoring(event.user, commandName)) { if(applyRegex(commandName, event)) { - dbot.commands[commandName](event); + try { + dbot.commands[commandName](event); + } catch(err) { + if(dbot.config.debugMode == true) { + event.reply('- Error in ' + commandName + ':'); + event.reply('- Message: ' + err); + event.reply('- Top of stack: ' + err.stack.split('\n')[1].trim()); + } + } dbot.save(); } else { if(commandName !== '~') { diff --git a/run.js b/run.js index e9e5132..187996d 100644 --- a/run.js +++ b/run.js @@ -5,7 +5,7 @@ require('./snippets'); var DBot = function(timers) { // Load external files - var requiredConfigKeys = [ 'name', 'servers', 'admins', 'moduleNames', 'language' ]; + var requiredConfigKeys = [ 'name', 'servers', 'admins', 'moduleNames', 'language', 'debugMode' ]; try { this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); } catch(err) {