Handle invalid history timestamps.

This commit is contained in:
Florian Bruhin 2015-08-01 00:57:34 +02:00
parent 9167d3ef17
commit cc66feac09

View File

@ -23,7 +23,7 @@ import datetime
from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtCore import pyqtSlot, Qt
from qutebrowser.utils import objreg, utils, qtutils from qutebrowser.utils import objreg, utils, qtutils, log
from qutebrowser.completion.models import base from qutebrowser.completion.models import base
from qutebrowser.config import config from qutebrowser.config import config
@ -80,7 +80,14 @@ class UrlCompletionModel(base.BaseCompletionModel):
fmt = config.get('completion', 'timestamp-format') fmt = config.get('completion', 'timestamp-format')
if fmt is None: if fmt is None:
return '' return ''
return datetime.datetime.fromtimestamp(atime).strftime(fmt) try:
dt = datetime.datetime.fromtimestamp(atime)
except (ValueError, OSError, OverflowError):
# Different errors which can occur for too large values...
log.misc.error("Got invalid timestamp {}!".format(atime))
return '(invalid)'
else:
return dt.strftime(fmt)
def _add_history_entry(self, entry): def _add_history_entry(self, entry):
"""Add a new history entry to the completion.""" """Add a new history entry to the completion."""