diff options
author | Sascha Silbe <sascha-pgp@silbe.org> | 2010-10-17 09:36:09 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha-pgp@silbe.org> | 2010-11-30 10:37:10 (GMT) |
commit | 923a7fce4e1d3e9038ea5917275df1eb191966d9 (patch) | |
tree | 254a38858ba087851fc43cf5454b04be4ab5cd7d | |
parent | 79c85ed25efaa6eed02589467fa96145795c1205 (diff) |
Journal details view: don't choke on invalid timestamp (SL#1590, SL#2208)
Metadata can get corrupted by crashes or malformed by buggy activities.
We should do our best to display the parts that are usable.
Acked-by: Simon Schampijer <simon@schampijer.de>
-rw-r--r-- | src/jarabe/journal/expandedentry.py | 13 | ||||
-rw-r--r-- | src/jarabe/journal/misc.py | 16 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py index 0c60600..fe2f320 100644 --- a/src/jarabe/journal/expandedentry.py +++ b/src/jarabe/journal/expandedentry.py @@ -281,10 +281,15 @@ class ExpandedEntry(hippo.CanvasBox): def _format_date(self): if 'timestamp' in self._metadata: - timestamp = float(self._metadata['timestamp']) - return time.strftime('%x', time.localtime(timestamp)) - else: - return _('No date') + try: + timestamp = float(self._metadata['timestamp']) + except (ValueError, TypeError): + logging.warning('Invalid timestamp for %r: %r', + self._metadata['uid'], + self._metadata['timestamp']) + else: + return time.strftime('%x', time.localtime(timestamp)) + return _('No date') def _create_buddy_list(self): diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py index d13aab0..b01c671 100644 --- a/src/jarabe/journal/misc.py +++ b/src/jarabe/journal/misc.py @@ -90,12 +90,20 @@ def get_icon_name(metadata): def get_date(metadata): """ Convert from a string in iso format to a more human-like format. """ if 'timestamp' in metadata: - timestamp = float(metadata['timestamp']) - return util.timestamp_to_elapsed_string(timestamp) + try: + timestamp = float(metadata['timestamp']) + except (TypeError, ValueError): + logging.warning('Invalid timestamp: %r', metadata['timestamp']) + else: + return util.timestamp_to_elapsed_string(timestamp) if 'mtime' in metadata: - ti = time.strptime(metadata['mtime'], '%Y-%m-%dT%H:%M:%S') - return util.timestamp_to_elapsed_string(time.mktime(ti)) + try: + ti = time.strptime(metadata['mtime'], '%Y-%m-%dT%H:%M:%S') + except (TypeError, ValueError): + logging.warning('Invalid mtime: %r', metadata['mtime']) + else: + return util.timestamp_to_elapsed_string(time.mktime(ti)) return _('No date') |