Skip to content

Commit

Permalink
Merge pull request CloudBotIRC#223 from linuxdaemon/gonzobot+hook-errors
Browse files Browse the repository at this point in the history
Add logging of hook errors to configurable log channel
  • Loading branch information
edwardslabs authored Nov 21, 2017
2 parents 2ee3ce3 + b60e8bc commit f1470fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cloudbot/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ def internal_launch(self, hook, event):
try:
out = yield from task
ok = True
except Exception as e:
except Exception:
logger.exception("Error in hook {}".format(hook.description))
ok = False
out = e
out = sys.exc_info()

hook.plugin.tasks.remove(task)

Expand Down
23 changes: 23 additions & 0 deletions plugins/core/chan_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import traceback

from cloudbot import hook
from cloudbot.util import web

logchannel = ""


@hook.post_hook
def on_hook_end(error, message, launched_hook, launched_event):
if error is not None and logchannel:
message("Error occurred in {}.{}".format(launched_hook.plugin.title, launched_hook.function_name), logchannel)

lines = traceback.format_exception(*error)
last_line = lines[-1]
message(last_line, logchannel)
url = web.paste('\n'.join(lines))
message("Traceback: " + url, logchannel)

event_data = launched_event.__dict__.items()
lines = ["{} = {}".format(k, v) for k, v in event_data]
url = web.paste('\n'.join(lines))
message("Event: " + url, logchannel)

0 comments on commit f1470fa

Please sign in to comment.