[core/module] only log an error when a module cannot be loaded

improve logging of import errors

see #606
This commit is contained in:
tobi-wan-kenobi 2020-05-02 13:29:20 +02:00
parent 9b63345b44
commit bac38ece5d

View file

@ -1,3 +1,4 @@
import os
import importlib import importlib
import logging import logging
@ -19,11 +20,10 @@ def load(module_name, config=core.config.Config([]), theme=None):
for namespace in [ 'core', 'contrib' ]: for namespace in [ 'core', 'contrib' ]:
try: try:
mod = importlib.import_module('modules.{}.{}'.format(namespace, module_short)) mod = importlib.import_module('modules.{}.{}'.format(namespace, 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.fatal('failed to import {}: {}'.format(module_short, e)) error = e
if not error or module_short in error:
error = str(e)
log.fatal('failed to import {}: {}'.format(module_name, error)) log.fatal('failed to import {}: {}'.format(module_name, error))
return Error(config=config, module=module_name, error=error) return Error(config=config, module=module_name, error=error)