Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha-pgp@silbe.org>2010-10-17 08:59:41 (GMT)
committer Sascha Silbe <sascha-pgp@silbe.org>2010-11-30 10:36:33 (GMT)
commit79c85ed25efaa6eed02589467fa96145795c1205 (patch)
tree3e0c248eeada0d8730c2df48cb945245cbef0340
parenta2e1f09c001a9d4ec5399934372e3afb5322cf63 (diff)
Journal list view: don't choke on invalid or incomplete metadata (SL#1408)
Metadata can get corrupted by crashes or malformed by buggy activities. We should do our best to display the parts that are usable and certainly never mess up the entire Journal. Acked-by: Simon Schampijer <simon@schampijer.de>
-rw-r--r--src/jarabe/journal/listmodel.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/jarabe/journal/listmodel.py b/src/jarabe/journal/listmodel.py
index 55f83f4..cef636e 100644
--- a/src/jarabe/journal/listmodel.py
+++ b/src/jarabe/journal/listmodel.py
@@ -140,11 +140,16 @@ class ListModel(gtk.GenericTreeModel, gtk.TreeDragSource):
xo_color = misc.get_icon_color(metadata)
self._cached_row.append(xo_color)
- title = gobject.markup_escape_text(metadata.get('title', None))
- self._cached_row.append('<b>%s</b>' % title)
+ title = gobject.markup_escape_text(metadata.get('title',
+ _('Untitled')))
+ self._cached_row.append('<b>%s</b>' % (title, ))
- timestamp = int(metadata.get('timestamp', 0))
- self._cached_row.append(util.timestamp_to_elapsed_string(timestamp))
+ try:
+ timestamp = float(metadata.get('timestamp', 0))
+ except (TypeError, ValueError):
+ self._cached_row.append(_('Unknown'))
+ else:
+ self._cached_row.append(util.timestamp_to_elapsed_string(timestamp))
try:
creation_time = float(metadata.get('creation_time'))
@@ -161,19 +166,37 @@ class ListModel(gtk.GenericTreeModel, gtk.TreeDragSource):
else:
self._cached_row.append(util.format_size(size))
- self._cached_row.append(int(metadata.get('progress', 100)))
-
- if metadata.get('buddies', ''):
- buddies = simplejson.loads(metadata['buddies']).values()
- else:
+ try:
+ progress = int(float(metadata.get('progress', 100)))
+ except (TypeError, ValueError):
+ progress = 100
+ self._cached_row.append(progress)
+
+ buddies = []
+ if metadata.get('buddies'):
+ try:
+ buddies = simplejson.loads(metadata['buddies']).values()
+ except simplejson.decoder.JSONDecodeError, exception:
+ logging.warning('Cannot decode buddies for %r: %s',
+ metadata['uid'], exception)
+
+ if not isinstance(buddies, list):
+ logging.warning('Content of buddies for %r is not a list: %r',
+ metadata['uid'], buddies)
buddies = []
for n_ in xrange(0, 3):
if buddies:
- nick, color = buddies.pop(0)
- self._cached_row.append((nick, XoColor(color)))
- else:
- self._cached_row.append(None)
+ try:
+ nick, color = buddies.pop(0)
+ except (AttributeError, ValueError), exception:
+ logging.warning('Malformed buddies for %r: %s',
+ metadata['uid'], exception)
+ else:
+ self._cached_row.append((nick, XoColor(color)))
+ continue
+
+ self._cached_row.append(None)
return self._cached_row[column]