From 343d8925f6e7986267d6e8c09738a0b503357380 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Tue, 30 Aug 2016 10:27:55 -0500 Subject: [PATCH 1/2] Add exception handling for cached forts --- pokemongo_bot/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index de996f3df3..a69eb4b0ba 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -1313,8 +1313,16 @@ def _load_recent_forts(self): cached_forts_path = os.path.join(_base_dir, 'data', 'recent-forts-%s.json' % self.config.username) try: # load the cached recent forts - with open(cached_forts_path) as f: - cached_recent_forts = json.load(f) + + cached_recent_forts = [] + try: + with open(cached_forts_path) as f: + cached_recent_forts = json.load(f) + except (IOError, ValueError) as e: + self.bot.logger.info('[x] Error while opening cached forts: %s' % e, 'red') + pass + except: + raise FileIOException("Unexpected error opening {}".cached_forts_path) num_cached_recent_forts = len(cached_recent_forts) num_recent_forts = len(self.recent_forts) From 861bc94ca5e7d2f8fc94f8920c385df83e2b8544 Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Tue, 30 Aug 2016 10:39:28 -0500 Subject: [PATCH 2/2] whitespace fix --- pokemongo_bot/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 8c77d112fb..fb288cfc37 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -1317,7 +1317,6 @@ def _load_recent_forts(self): cached_forts_path = os.path.join(_base_dir, 'data', 'recent-forts-%s.json' % self.config.username) try: # load the cached recent forts - cached_recent_forts = [] try: with open(cached_forts_path) as f: