From bbb32607ed7faa18f2fdaa6d7376ee729a88b041 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 20 Mar 2018 01:06:05 +0200 Subject: [PATCH] Catch UnicodeError when saving content cache --- platformio/app.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/platformio/app.py b/platformio/app.py index dd7922f0..61e15491 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -210,10 +210,17 @@ class ContentCache(object): if not isdir(dirname(cache_path)): os.makedirs(dirname(cache_path)) - with codecs.open(cache_path, "wb") as fp: - fp.write(str(data)) - with codecs.open(self._db_path, "a") as fp: - fp.write("%s=%s\n" % (str(expire_time), cache_path)) + try: + with codecs.open(cache_path, "wb") as fp: + fp.write(data) + with codecs.open(self._db_path, "a") as fp: + fp.write("%s=%s\n" % (str(expire_time), cache_path)) + except UnicodeError: + if isfile(cache_path): + try: + remove(cache_path) + except OSError: + pass return self._unlock_dbindex()