[core/module] Fix error display

This commit is contained in:
Tobias Witek 2020-02-15 14:04:53 +01:00
parent 5d971267db
commit 99cca7002c

View file

@ -2,6 +2,7 @@ import importlib
import logging import logging
import core.input import core.input
import core.widget
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -9,8 +10,8 @@ def load(module_name, config=None):
try: try:
mod = importlib.import_module('modules.{}'.format(module_name)) mod = importlib.import_module('modules.{}'.format(module_name))
except ImportError as error: except ImportError as error:
log.fatal('failed to import {}: {}'.format(module_name, str(error))) log.fatal('failed to import {}: {}'.format(module_name, error))
return Error(module_name) return Error(config, module_name, error)
return getattr(mod, 'Module')(config) return getattr(mod, 'Module')(config)
class Module(core.input.Object): class Module(core.input.Object):
@ -41,7 +42,12 @@ class Module(core.input.Object):
return self._widgets return self._widgets
class Error(Module): class Error(Module):
def __init__(self, loaded_module_name): def __init__(self, config, module, error):
self._loaded_module_name = loaded_module_name super().__init__(config, core.widget.Widget(self.full_text))
self._module = module
self._error = error
def full_text(self):
return '{}: {}'.format(self._module, self._error)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4