[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:
|
||||
mod = importlib.import_module('modules.{}.{}'.format(namespace, module_short))
|
||||
return getattr(mod, 'Module')(config)
|
||||
except ModuleNotFoundError as e:
|
||||
log.fatal('failed to import {}: {}'.format(module_short, e))
|
||||
except ImportError as e:
|
||||
log.fatal('failed to import {}: {}'.format(module_short, e))
|
||||
error = str(e)
|
||||
if not error:
|
||||
error = 'No such module'
|
||||
if not error or module_short in error:
|
||||
error = str(e)
|
||||
log.fatal('failed to import {}: {}'.format(module_name, error))
|
||||
return Error(config=config, module=module_name, error=error)
|
||||
|
||||
|
|
Loading…
Reference in a new issue