From 0e22bb4316ab58c8a9a0abcf80dba8c8e2f17309 Mon Sep 17 00:00:00 2001 From: pictuga Date: Sun, 28 Sep 2014 12:03:58 +0200 Subject: [PATCH] Cache: catch json parse erros --- morss/morss.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/morss/morss.py b/morss/morss.py index 14741fa..34f7ee0 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -145,10 +145,14 @@ class Cache: self._file = self._dir + '/' + self._hash self._file_tmp = self._file + '.tmp' - if os.path.isfile(self._file): + try: data = open(self._file).read() if data: self._cache = json.loads(data) + except IOError: + pass + except ValueError: + log('JSON cache parse fail') def __del__(self): self.save()