From 572c34b821ab2e28487fde17125ecf0f074e6f42 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 Apr 2022 07:32:15 +0530 Subject: [PATCH] Fix #1968767 [JSONDecode Error when turning pages with space bar in the E-Book Viewer](https://bugs.launchpad.net/calibre/+bug/1968767) --- src/calibre/gui2/viewer/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/viewer/config.py b/src/calibre/gui2/viewer/config.py index 94687cafcd..2fc31abfca 100644 --- a/src/calibre/gui2/viewer/config.py +++ b/src/calibre/gui2/viewer/config.py @@ -38,13 +38,17 @@ def reading_rates_path(): def save_reading_rates(key, rates): path = reading_rates_path() + existing = {} try: with open(path, 'rb') as f: raw = f.read() except OSError: - existing = {} + pass else: - existing = json.loads(raw) + try: + existing = json.loads(raw) + except Exception: + pass existing.pop(key, None) existing[key] = rates while len(existing) > 50: