diff options
author | Sascha Silbe <sascha-pgp@silbe.org> | 2010-10-17 09:36:09 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha-pgp@silbe.org> | 2010-10-23 11:06:41 (GMT) |
commit | 518f7c478fd9ea4d8bbfd6218ae699f7e14d7061 (patch) | |
tree | bb20c1254279c9d9bca72e429fe16eac27d531e1 | |
parent | cdbab7d921b57c9dcf52a60db997854024fc148f (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.
-rw-r--r-- | src/jarabe/journal/expandedentry.py | 12 | ||||
-rw-r--r-- | src/jarabe/journal/misc.py | 16 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py index 0c60600..0abf8ab 100644 --- a/src/jarabe/journal/expandedentry.py +++ b/src/jarabe/journal/expandedentry.py @@ -281,10 +281,14 @@ 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 619fe43..4fcfc60 100644 --- a/src/jarabe/journal/misc.py +++ b/src/jarabe/journal/misc.py @@ -87,12 +87,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') |