From 944748a0acbd3b5d64e9f8c916f02b2954db6e3d Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 6 Oct 2020 21:09:25 -0700 Subject: [PATCH] Don't throw away exception info on save/load. Makes it much easier to determine what we did that broke save game compatibility. --- game/persistency.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/game/persistency.py b/game/persistency.py index 4e0b216f..617274ea 100644 --- a/game/persistency.py +++ b/game/persistency.py @@ -41,30 +41,33 @@ def restore_game(): try: save = pickle.load(f) return save - except: - logging.error("Invalid Save game") + except Exception: + logging.exception("Invalid Save game") return None + def load_game(path): with open(path, "rb") as f: try: save = pickle.load(f) save.savepath = path return save - except: - logging.error("Invalid Save game") + except Exception: + logging.exception("Invalid Save game") return None + def save_game(game) -> bool: try: with open(_temporary_save_file(), "wb") as f: pickle.dump(game, f) shutil.copy(_temporary_save_file(), game.savepath) return True - except Exception as e: - logging.error(e) + except Exception: + logging.exception("Could not save game") return False + def autosave(game) -> bool: """ Autosave to the autosave location @@ -75,7 +78,7 @@ def autosave(game) -> bool: with open(_autosave_path(), "wb") as f: pickle.dump(game, f) return True - except Exception as e: - logging.error(e) + except Exception: + logging.exception("Could not save game") return False