From e80b695dfa43d7bd03448eac61fba11d06cd534e Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 8 Sep 2013 10:51:21 +0000 Subject: [PATCH] crash error reporting [#468] --- modules/log/log.js | 29 ++++++++++++++++++++++++++++- modules/log/strings.json | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/log/log.js b/modules/log/log.js index 5f9b07a..f7c77c0 100644 --- a/modules/log/log.js +++ b/modules/log/log.js @@ -2,7 +2,8 @@ * Name: Log * Description: Log commands to a channel. */ -var _ = require('underscore')._; +var _ = require('underscore')._, + process = require('process'); var log = function(dbot) { this.ignoredCommands = []; @@ -18,6 +19,25 @@ var log = function(dbot) { })); }, + 'logError': function(server, err) { + var stack = err.stack.split('\n').slice(1, dbot.config.debugLevel + 1), + logChannel = this.config.logChannel[server], + time = new Date().toUTCString(); + + dbot.say(server, logChannel, dbot.t('error_message', { + 'time': time, + 'error': 'Message: ' + err + })); + + _.each(stack, function(stackLine, index) { + dbot.say(server, logChannel, dbot.t('error_message', { + 'time': time, + 'error': 'Stack[' + index + ']: ' + + stackLine.trim() + })); + }); + }, + 'ignoreCommand': function(commandName) { this.ignoredCommands.push(commandName); } @@ -36,6 +56,13 @@ var log = function(dbot) { })); } }.bind(this)); + + process.on('uncaughtException', function(err) { + _.each(this.config.logChannel, function(chan, server) { + this.api.logError(server, err); + }, this); + process.exit(1); + }.bind(this)); }.bind(this); }; diff --git a/modules/log/strings.json b/modules/log/strings.json index cb70d42..bab6cba 100644 --- a/modules/log/strings.json +++ b/modules/log/strings.json @@ -3,5 +3,7 @@ "en": "[{time}] {user} ({channel}): {command}", "fr": "[{time}] {user} ({channel}): {command}", "it": "[{time}] {user} ({channel}): {command}" + }, + "en": "[{time}] Error: {error}" } }