From dc06611fb12da575534f3a83672e7ed6ca871d3b Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 10 Jun 2017 13:59:44 +0200 Subject: [PATCH] [modules] weather & github: Protect against missing data If data cannot be retrieved for some reason (be pretty generous about that by catching generic exceptions), instead of terminating the whole status bar, simply report unknown data. see #110 --- bumblebee/modules/github.py | 12 ++++++++---- bumblebee/modules/weather.py | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bumblebee/modules/github.py b/bumblebee/modules/github.py index 891c3e2..7a64594 100644 --- a/bumblebee/modules/github.py +++ b/bumblebee/modules/github.py @@ -44,9 +44,13 @@ class Module(bumblebee.engine.Module): notifications = requests.get("https://api.github.com/notifications", headers={"Authorization":"token {}".format(token)}).text unread = 0 - for notification in json.loads(notifications): - if "unread" in notification and notification["unread"]: - unread += 1 - self._count = unread + try: + for notification in json.loads(notifications): + if "unread" in notification and notification["unread"]: + unread += 1 + self._count = unread + except Exception: + self._count = "n/a" + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/modules/weather.py b/bumblebee/modules/weather.py index 683f61d..01420e3 100644 --- a/bumblebee/modules/weather.py +++ b/bumblebee/modules/weather.py @@ -70,5 +70,7 @@ class Module(bumblebee.engine.Module): self._valid = True except RequestException: self._valid = False + except Exception: + self._valid = False # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4