Catch exception during module loading: just skip the module registration
This commit is contained in:
parent
91688875d4
commit
c1858fff3a
3 changed files with 15 additions and 12 deletions
|
|
@ -385,14 +385,16 @@ class Bot(threading.Thread):
|
||||||
module.__nemubot_context__.add_hook(s, h)
|
module.__nemubot_context__.add_hook(s, h)
|
||||||
nemubot.hooks.last_registered = []
|
nemubot.hooks.last_registered = []
|
||||||
|
|
||||||
# Save a reference to the module
|
|
||||||
self.modules[module_name] = module
|
|
||||||
|
|
||||||
# Launch the module
|
# Launch the module
|
||||||
if hasattr(module, "load"):
|
if hasattr(module, "load"):
|
||||||
|
try:
|
||||||
module.load(module.__nemubot_context__)
|
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):
|
def unload_module(self, name):
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,8 @@ class ModuleLoader(SourceFileLoader):
|
||||||
|
|
||||||
def _load(self, module, name):
|
def _load(self, module, name):
|
||||||
# Add the module to the global modules list
|
# Add the module to the global modules list
|
||||||
if self.add_module(module):
|
self.add_module(module)
|
||||||
logger.info("Module '%s' successfully loaded.", name)
|
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)
|
|
||||||
return module
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,12 @@ def load_file(filename, context):
|
||||||
for mod in config.getNodes("module"):
|
for mod in config.getNodes("module"):
|
||||||
context.modules_configuration[mod["name"]] = mod
|
context.modules_configuration[mod["name"]] = mod
|
||||||
if get_boolean(mod, "autoload", default=True):
|
if get_boolean(mod, "autoload", default=True):
|
||||||
|
try:
|
||||||
__import__(mod["name"])
|
__import__(mod["name"])
|
||||||
|
except:
|
||||||
|
logger.exception("Exception occurs when loading module"
|
||||||
|
" '%s'", mod["name"])
|
||||||
|
|
||||||
|
|
||||||
# Load files asked by the configuration file
|
# Load files asked by the configuration file
|
||||||
for load in config.getNodes("include"):
|
for load in config.getNodes("include"):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue