Catch exception during module loading: just skip the module registration
This commit is contained in:
parent
91688875d4
commit
c1858fff3a
|
@ -385,14 +385,16 @@ class Bot(threading.Thread):
|
|||
module.__nemubot_context__.add_hook(s, h)
|
||||
nemubot.hooks.last_registered = []
|
||||
|
||||
# Save a reference to the module
|
||||
self.modules[module_name] = module
|
||||
|
||||
# Launch the module
|
||||
if hasattr(module, "load"):
|
||||
module.load(module.__nemubot_context__)
|
||||
try:
|
||||
module.load(module.__nemubot_context__)
|
||||
except:
|
||||
module.__nemubot_context__.unload()
|
||||
raise
|
||||
|
||||
return True
|
||||
# Save a reference to the module
|
||||
self.modules[module_name] = module
|
||||
|
||||
|
||||
def unload_module(self, name):
|
||||
|
|
|
@ -57,12 +57,8 @@ class ModuleLoader(SourceFileLoader):
|
|||
|
||||
def _load(self, module, name):
|
||||
# Add the module to the global modules list
|
||||
if self.add_module(module):
|
||||
logger.info("Module '%s' successfully loaded.", name)
|
||||
else:
|
||||
logger.error("An error occurs while importing `%s'.", name)
|
||||
raise ImportError("An error occurs while importing `%s'."
|
||||
% name)
|
||||
self.add_module(module)
|
||||
logger.info("Module '%s' successfully loaded.", name)
|
||||
return module
|
||||
|
||||
|
||||
|
|
|
@ -117,7 +117,12 @@ def load_file(filename, context):
|
|||
for mod in config.getNodes("module"):
|
||||
context.modules_configuration[mod["name"]] = mod
|
||||
if get_boolean(mod, "autoload", default=True):
|
||||
__import__(mod["name"])
|
||||
try:
|
||||
__import__(mod["name"])
|
||||
except:
|
||||
logger.exception("Exception occurs when loading module"
|
||||
" '%s'", mod["name"])
|
||||
|
||||
|
||||
# Load files asked by the configuration file
|
||||
for load in config.getNodes("include"):
|
||||
|
|
Loading…
Reference in New Issue
Block a user