From: John Runyon Date: Mon, 23 Oct 2023 13:55:00 +0000 (-0600) Subject: exception_hook module X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/e33fc813275985611109b5731fd94a79fb12ba0f exception_hook module --- diff --git a/modules/exception_hook.py b/modules/exception_hook.py new file mode 100644 index 0000000..5c089ea --- /dev/null +++ b/modules/exception_hook.py @@ -0,0 +1,29 @@ +# Erebus IRC bot - Author: Erebus Team +# vim: fileencoding=utf-8 +# This file is released into the public domain; see http://unlicense.org/ + +# module info +modinfo = { + 'author': 'Erebus Team', + 'license': 'public domain', + 'compatible': [0], # compatible module API versions + 'depends': [], # other modules required to work properly? + 'softdeps': [], # modules which are preferred but not required +} + +# preamble +import modlib +lib = modlib.modlib(__name__) +modstart = lib.modstart +modstop = lib.modstop + +# module code +import traceback + +@lib.hookexception(Exception) +def got_exception(bot, exc, source, *args, **kwargs): + dest = lib.parent.cfg.get('exception_hook', 'destination') + if dest is not None: + bot.msg(dest, '%s exception: %r %r' % (source, args, kwargs)) + for line in traceback.format_exc(limit=lib.parent.cfg.getint('exception_hook', 'limit', 5)).split("\n"): + bot.msg(dest, (' '*4) + line)