From 1359f1000fb9f4b556427d6a45ec6c6b8489cbef Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 1 Mar 2019 21:02:51 +0100 Subject: [PATCH] [engine] Nicer handling of module exceptions Do not throw exceptions during exception handling, that causes really hard-to-interpret error messages. Instead, log a message and throw outside the exception handler (the code could do with some cleanup, but is localized enough for now). see #367 --- bumblebee/engine.py | 6 +++++- bumblebee/modules/nic.py | 10 ++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/bumblebee/engine.py b/bumblebee/engine.py index f515470..2efa2d4 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -241,10 +241,14 @@ class Engine(object): module_name = self._aliases[module_name] if config_name is None: config_name = module_name + err = None try: module = importlib.import_module("bumblebee.modules.{}".format(module_name)) except ImportError as error: - raise bumblebee.error.ModuleLoadError(error) + err = error + log.fatal("failed to import {}: {}".format(module_name, str(error))) + if err: + raise bumblebee.error.ModuleLoadError("unable to load module {}: {}".format(module_name, str(err))) return getattr(module, "Module")(self, { "name": config_name, "config": self._config diff --git a/bumblebee/modules/nic.py b/bumblebee/modules/nic.py index 1e37e2b..15cb4d9 100644 --- a/bumblebee/modules/nic.py +++ b/bumblebee/modules/nic.py @@ -11,14 +11,8 @@ Parameters: * nic.format: Format string (defaults to "{intf} {state} {ip} {ssid}") """ -import logging -log = logging.getLogger(__name__) - -try: - import netifaces - import subprocess -except ImportError as e: - log.warning("failed to import nic: {}".format(e)) +import netifaces +import subprocess21 import bumblebee.util import bumblebee.input