From 04e7f952d3c1a81916fd6fad2c1cc07d0a8655f3 Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Wed, 2 Nov 2016 15:18:32 -0400 Subject: [PATCH] Improve error handler --- src/decorators.py | 15 +++++---------- src/utilities.py | 6 +++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/decorators.py b/src/decorators.py index c9b061f..d787086 100644 --- a/src/decorators.py +++ b/src/decorators.py @@ -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() diff --git a/src/utilities.py b/src/utilities.py index 4a46bb4..8d091ea 100644 --- a/src/utilities.py +++ b/src/utilities.py @@ -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