From bf84498df3e37b3ceb17d59f621b8e559cf7980a Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 12 Jan 2018 18:39:36 +0100 Subject: [PATCH] [core/engine] handle single-module errors instead of terminating the whole status bar when an error occurs, just show a (truncated) error for that single widget. this should also enable auto-recovery if the module returns to a "good" state, but that hasn't been tested yet. see #221 and #222 --- bumblebee/engine.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/bumblebee/engine.py b/bumblebee/engine.py index df5b0da..c40fc1c 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -38,6 +38,7 @@ class Module(object): self.name = config.get("name", self.__module__.split(".")[-1]) self._config = config self.id = self.name + self.error = None self._next = int(time.time()) self._default_interval = 0 @@ -67,6 +68,12 @@ class Module(object): if widget.name == name: return widget + def errorWidget(self): + msg = self.error + if len(msg) > 10: + msg = "{}...".format(msg[0:7]) + return bumblebee.output.Widget(full_text="error: {}".format(msg)) + def widget_by_id(self, uid): for widget in self._widgets: if widget.id == uid: @@ -80,7 +87,12 @@ class Module(object): def update_wrapper(self, widgets): if self._next > int(time.time()): return - self.update(self._widgets) + try: + self.error = None + self.update(self._widgets) + except Exception as e: + log.error("error updating '{}': {}".format(self.name, str(e))) + self.error = str(e) self._next += int(self.parameter("interval", self._default_interval))*60 def interval(self, intvl): @@ -244,9 +256,12 @@ class Engine(object): for module in self._modules: self._current_module = module module.update_wrapper(module.widgets()) - for widget in module.widgets(): - widget.link_module(module) - self._output.draw(widget=widget, module=module, engine=self) + if module.error == None: + for widget in module.widgets(): + widget.link_module(module) + self._output.draw(widget=widget, module=module, engine=self) + else: + self._output.draw(widget=module.errorWidget(), module=module, engine=self) self._output.flush() self._output.end() if self.running():