From 1a5a32449845ea8d74bf0a6ccd27e0f4bc61b0ef Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sat, 11 Apr 2020 12:59:39 +0200 Subject: [PATCH] [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". --- core/module.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/module.py b/core/module.py index 0152b5e..6e48213 100644 --- a/core/module.py +++ b/core/module.py @@ -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)