[Sugar-devel] [PATCH sugar] Journal details view: don't choke on invalid timestamp (SL#1590, SL#2208)
Sascha Silbe
sascha-pgp at silbe.org
Sun Oct 17 06:04:17 EDT 2010
Metadata can get corrupted by crashes or malformed by buggy activities.
We should do our best to display the parts that are usable.
Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>
---
src/jarabe/journal/expandedentry.py | 12 ++++++++----
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')
--
1.7.1
More information about the Sugar-devel
mailing list