From: zonidjan Date: Sun, 6 Sep 2015 01:47:52 +0000 (-0500) Subject: fix crashbug in !modreload / ctlmod.reloadmod X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/e38786129fcb0d996fa7e00bb0d06e359b3e090e fix crashbug in !modreload / ctlmod.reloadmod previously a typo or etc could've crashed the bot (due to ImportError; not finding the requested module) --- diff --git a/ctlmod.py b/ctlmod.py index 9a30c7e..73ae1fc 100644 --- a/ctlmod.py +++ b/ctlmod.py @@ -59,13 +59,17 @@ def reloadmod(parent, modname): if modhas(modname, 'modrestart'): modules[modname].modrestart(parent) else: modules[modname].modstop(parent) - reload(modules[modname]) + try: + return reload(modules[modname]) + except BaseException, e: + return modlib.error(e) if modhas(modname, 'modrestarted'): modules[modname].modrestarted(parent) else: modules[modname].modstart(parent) else: - load(parent, modname) + return load(parent, modname) + def loadall(parent, modlist): for m in modlist: load(parent, m) diff --git a/modlib.py b/modlib.py index 5fb7e77..02b657e 100644 --- a/modlib.py +++ b/modlib.py @@ -10,7 +10,7 @@ class error(object): def __repr__(self): return '' % self.errormsg def __str__(self): - return self.errormsg + return str(self.errormsg) class modlib(object): # default (global) access levels diff --git a/modules/module.py b/modules/module.py index 33be1ff..bcccaa2 100644 --- a/modules/module.py +++ b/modules/module.py @@ -41,7 +41,10 @@ def cmd_modunload(bot, user, chan, realtarget, *args): @lib.argsEQ(1) def cmd_modreload(bot, user, chan, realtarget, *args): okay = ctlmod.reloadmod(bot.parent, args[0]) - bot.msg(user, "Reloaded %s" % (args[0])) + if okay: + bot.msg(user, "Reloaded %s" % (args[0])) + else: + bot.msg(user, "Error occurred: %r" % (okay)) @lib.hook('modlist', needchan=False, glevel=lib.STAFF) @lib.argsEQ(0)