From a27c284869eef0cd4262d7a92aa499a9906b6ead Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sun, 17 Jan 2021 15:29:44 +0100 Subject: [PATCH] [core/module] fix failing unit test wrong error handling again --- bumblebee_status/core/module.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/bumblebee_status/core/module.py b/bumblebee_status/core/module.py index 9239a49..6987129 100644 --- a/bumblebee_status/core/module.py +++ b/bumblebee_status/core/module.py @@ -17,8 +17,6 @@ except Exception as e: log = logging.getLogger(__name__) -import sys - """Loads a module by name :param module_name: Name of the module to load @@ -47,16 +45,16 @@ def load(module_name, config=core.config.Config([]), theme=None): return getattr(mod, "Module")(config, theme) except ImportError as e: usermod = os.path.expanduser("~/.config/bumblebee-status/modules/{}.py".format(module_short)) - if not os.path.exists(usermod): - raise e - try: - log.warning("failed to import {} from system: {}".format(module_short, e)) - mod = importlib.machinery.SourceFileLoader("modules.{}".format(module_short), - os.path.expanduser(usermod)).load_module() - log.debug("importing {} from user".format(module_short)) - return getattr(mod, "Module")(config, theme) - except ImportError as e: - log.fatal("failed to import {}: {}".format(module_short, e)) + if os.path.exists(usermod): + try: + log.warning("failed to import {} from system: {}".format(module_short, e)) + mod = importlib.machinery.SourceFileLoader("modules.{}".format(module_short), + os.path.expanduser(usermod)).load_module() + log.debug("importing {} from user".format(module_short)) + return getattr(mod, "Module")(config, theme) + except ImportError as e: + log.fatal("import failed: {}".format(e)) + log.fatal("failed to import {}".format(module_short)) return Error(config=config, module=module_name, error="unable to load module")