]> jfr.im git - erebus.git/blame - modules/exception_hook.py
exception_hook - fix traceback to show last <limit> lines instead of first
[erebus.git] / modules / exception_hook.py
CommitLineData
e33fc813
JR
1# Erebus IRC bot - Author: Erebus Team
2# vim: fileencoding=utf-8
3# This file is released into the public domain; see http://unlicense.org/
4
5# module info
6modinfo = {
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [0], # compatible module API versions
10 'depends': [], # other modules required to work properly?
11 'softdeps': [], # modules which are preferred but not required
12}
13
14# preamble
15import modlib
16lib = modlib.modlib(__name__)
17modstart = lib.modstart
18modstop = lib.modstop
19
20# module code
21import traceback
22
23@lib.hookexception(Exception)
24def got_exception(bot, exc, source, *args, **kwargs):
25 dest = lib.parent.cfg.get('exception_hook', 'destination')
26 if dest is not None:
27 bot.msg(dest, '%s exception: %r %r' % (source, args, kwargs))
0778c029 28 for line in traceback.format_exc(limit=-lib.parent.cfg.getint('exception_hook', 'limit', 5)).split("\n"):
e33fc813 29 bot.msg(dest, (' '*4) + line)