Improve error handler

This commit is contained in:
Vgr E. Barry 2016-11-02 15:18:32 -04:00
parent 0120836669
commit 04e7f952d3
2 changed files with 8 additions and 13 deletions

View File

@ -12,7 +12,7 @@ from oyoyo.parse import parse_nick
import botconfig
import src.settings as var
from src.utilities import *
from src import logger, errlog, events
from src import channels, logger, errlog, events
from src.messages import messages
adminlog = logger.logger("audit.log")
@ -62,21 +62,16 @@ class handle_error:
fn = lambda: errlog("\n{0}\n\n".format(data))
data = traceback.format_exc()
cli = None
variables = ["\nLocal variables from innermost frame:"]
for name, value in _local.frame_locals.items():
if isinstance(value, IRCClient):
cli = value
variables.append("{0} = {1!r}".format(name, value))
data += "\n".join(variables)
if cli is not None:
if not botconfig.PASTEBIN_ERRORS or botconfig.CHANNEL != botconfig.DEV_CHANNEL:
cli.msg(botconfig.CHANNEL, messages["error_log"])
if botconfig.PASTEBIN_ERRORS and botconfig.DEV_CHANNEL:
pastebin_tb(cli, messages["error_log"], data)
if not botconfig.PASTEBIN_ERRORS or channels.Main is not channels.Dev:
channels.Main.send(messages["error_log"])
if botconfig.PASTEBIN_ERRORS and channels.Dev is not None:
pastebin_tb(channels.Dev, messages["error_log"], data, prefix=botconfig.DEV_PREFIX)
finally:
fn()

View File

@ -463,7 +463,7 @@ def get_nick(cli, nick):
return None
return ul[ull.index(lnick)]
def pastebin_tb(cli, msg, exc):
def pastebin_tb(context, msg, exc, prefix):
try:
bot_id = re.sub(r"[^A-Za-z0-9-]", "-", botconfig.NICK)
bot_id = re.sub(r"--+", "-", bot_id)
@ -484,9 +484,9 @@ def pastebin_tb(cli, msg, exc):
url = data["url"] + "/pytb"
except Exception:
# Exception is already printed before calling this function, don't print twice
cli.msg(botconfig.DEV_CHANNEL, msg + " (Unable to pastebin traceback; please check the console.)")
context.send(msg + " (Unable to pastebin traceback; please check the console.)", prefix=prefix)
else:
cli.msg(botconfig.DEV_CHANNEL, " ".join((msg, url)))
context.send(" ".join((msg, url)), prefix=prefix)
class InvalidModeException(Exception): pass