From 518f7c478fd9ea4d8bbfd6218ae699f7e14d7061 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Sun, 17 Oct 2010 09:36:09 +0000 Subject: 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. --- 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') -- cgit v0.9.1