Skip to content

Commit

Permalink
[modules] weather & github: Protect against missing data
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tobi-wan-kenobi committed Jun 10, 2017
1 parent b89e384 commit dc06611
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bumblebee/modules/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ def update(self, widgets):

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
2 changes: 2 additions & 0 deletions bumblebee/modules/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ def update(self, widgets):
self._valid = True
except RequestException:
self._valid = False
except Exception:
self._valid = False

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

0 comments on commit dc06611

Please sign in to comment.