[core/module] improved handling of import errors
Now, the error message includes the name of the module that was not imported, and there's checks to ensure the "more specific" error (i.e. a failing import *inside* the module) "wins".
This commit is contained in:
parent
801eceddd2
commit
1a5a324498
1 changed files with 2 additions and 5 deletions
|
@ -20,13 +20,10 @@ def load(module_name, config=core.config.Config([])):
|
||||||
try:
|
try:
|
||||||
mod = importlib.import_module('modules.{}.{}'.format(namespace, module_short))
|
mod = importlib.import_module('modules.{}.{}'.format(namespace, module_short))
|
||||||
return getattr(mod, 'Module')(config)
|
return getattr(mod, 'Module')(config)
|
||||||
except ModuleNotFoundError as e:
|
|
||||||
log.fatal('failed to import {}: {}'.format(module_short, e))
|
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
log.fatal('failed to import {}: {}'.format(module_short, e))
|
log.fatal('failed to import {}: {}'.format(module_short, e))
|
||||||
|
if not error or module_short in error:
|
||||||
error = str(e)
|
error = str(e)
|
||||||
if not error:
|
|
||||||
error = 'No such module'
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue