From a94114dd9496d801ce262bea721fa89436f7981c Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sat, 19 Dec 2020 13:07:29 +0100 Subject: [PATCH] [core/module] better error reporting for failed module loads if a module fails to load, explicitly log errors for core and contrib in the error log, but be a bit less verbose (and less confusing) in the module error message itself. fixes #747 --- bumblebee_status/core/module.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bumblebee_status/core/module.py b/bumblebee_status/core/module.py index f4bac7e..dad06e2 100644 --- a/bumblebee_status/core/module.py +++ b/bumblebee_status/core/module.py @@ -33,20 +33,20 @@ def load(module_name, config=core.config.Config([]), theme=None): error = None module_short, alias = (module_name.split(":") + [module_name])[0:2] config.set("__alias__", alias) - for namespace in ["core", "contrib"]: + + try: + mod = importlib.import_module("modules.core.{}".format(module_short)) + log.debug("importing {} from core".format(module_short)) + return getattr(mod, "Module")(config, theme) + except ImportError as e: try: - mod = importlib.import_module( - "modules.{}.{}".format(namespace, module_short) - ) - log.debug( - "importing {} from {}.{}".format(module_short, namespace, module_short) - ) + log.warning("failed to import {} from core: {}".format(module_short, e)) + mod = importlib.import_module("modules.contrib.{}".format(module_short)) + log.debug("importing {} from contrib".format(module_short)) return getattr(mod, "Module")(config, theme) except ImportError as e: - log.debug("failed to import {}: {}".format(module_name, e)) - error = e - log.fatal("failed to import {}: {}".format(module_name, error)) - return Error(config=config, module=module_name, error=error) + log.fatal("failed to import {} from contrib: {}".format(module_short, e)) + return Error(config=config, module=module_name, error="unable to load module") class Module(core.input.Object):