[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
This commit is contained in:
Tobias Witek 2019-03-01 21:02:51 +01:00
parent 8db3435ddc
commit 1359f1000f
2 changed files with 7 additions and 9 deletions

View file

@ -241,10 +241,14 @@ class Engine(object):
module_name = self._aliases[module_name] module_name = self._aliases[module_name]
if config_name is None: if config_name is None:
config_name = module_name config_name = module_name
err = None
try: try:
module = importlib.import_module("bumblebee.modules.{}".format(module_name)) module = importlib.import_module("bumblebee.modules.{}".format(module_name))
except ImportError as error: 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, { return getattr(module, "Module")(self, {
"name": config_name, "name": config_name,
"config": self._config "config": self._config

View file

@ -11,14 +11,8 @@ Parameters:
* nic.format: Format string (defaults to "{intf} {state} {ip} {ssid}") * nic.format: Format string (defaults to "{intf} {state} {ip} {ssid}")
""" """
import logging
log = logging.getLogger(__name__)
try:
import netifaces import netifaces
import subprocess import subprocess21
except ImportError as e:
log.warning("failed to import nic: {}".format(e))
import bumblebee.util import bumblebee.util
import bumblebee.input import bumblebee.input