[core/module] better error reporting for failed module loads
if a module fails to load, explicitly log errors for core and contrib in the error log, but be a bit less verbose (and less confusing) in the module error message itself. fixes #747
This commit is contained in:
parent
64355e5314
commit
a94114dd94
1 changed files with 11 additions and 11 deletions
|
@ -33,20 +33,20 @@ def load(module_name, config=core.config.Config([]), theme=None):
|
||||||
error = None
|
error = None
|
||||||
module_short, alias = (module_name.split(":") + [module_name])[0:2]
|
module_short, alias = (module_name.split(":") + [module_name])[0:2]
|
||||||
config.set("__alias__", alias)
|
config.set("__alias__", alias)
|
||||||
for namespace in ["core", "contrib"]:
|
|
||||||
try:
|
try:
|
||||||
mod = importlib.import_module(
|
mod = importlib.import_module("modules.core.{}".format(module_short))
|
||||||
"modules.{}.{}".format(namespace, module_short)
|
log.debug("importing {} from core".format(module_short))
|
||||||
)
|
|
||||||
log.debug(
|
|
||||||
"importing {} from {}.{}".format(module_short, namespace, module_short)
|
|
||||||
)
|
|
||||||
return getattr(mod, "Module")(config, theme)
|
return getattr(mod, "Module")(config, theme)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
log.debug("failed to import {}: {}".format(module_name, e))
|
try:
|
||||||
error = e
|
log.warning("failed to import {} from core: {}".format(module_short, e))
|
||||||
log.fatal("failed to import {}: {}".format(module_name, error))
|
mod = importlib.import_module("modules.contrib.{}".format(module_short))
|
||||||
return Error(config=config, module=module_name, error=error)
|
log.debug("importing {} from contrib".format(module_short))
|
||||||
|
return getattr(mod, "Module")(config, theme)
|
||||||
|
except ImportError as e:
|
||||||
|
log.fatal("failed to import {} from contrib: {}".format(module_short, e))
|
||||||
|
return Error(config=config, module=module_name, error="unable to load module")
|
||||||
|
|
||||||
|
|
||||||
class Module(core.input.Object):
|
class Module(core.input.Object):
|
||||||
|
|
Loading…
Reference in a new issue