Handle settings corruption issue

This commit is contained in:
RemixDev 2021-10-07 16:18:50 +02:00
parent 7e6202b7f0
commit 3b0763eeb1
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
2 changed files with 18 additions and 2 deletions

View File

@ -1,5 +1,6 @@
from concurrent.futures import ThreadPoolExecutor
import json
from copy import deepcopy
from pathlib import Path
import re
from urllib.request import urlopen
@ -309,7 +310,15 @@ class Spotify(Plugin):
json.dump({**self.credentials, **self.settings}, f, indent=2)
with open(self.configFolder / 'settings.json', 'r') as settingsFile:
settings = json.load(settingsFile)
try:
settings = json.load(settingsFile)
except json.decoder.JSONDecodeError:
with open(self.configFolder / 'settings.json', 'w') as f:
json.dump({**self.credentials, **self.settings}, f, indent=2)
settings = deepcopy({**self.credentials, **self.settings})
except Exception:
settings = deepcopy({**self.credentials, **self.settings})
self.setSettings(settings)
self.checkCredentials()

View File

@ -1,4 +1,5 @@
import json
from copy import deepcopy
from pathlib import Path
from os import makedirs
from deezer import TrackFormats
@ -113,7 +114,13 @@ def load(configFolder=None):
# Read config file
with open(configFolder / 'config.json', 'r') as configFile:
settings = json.load(configFile)
try:
settings = json.load(configFile)
except json.decoder.JSONDecodeError:
save(DEFAULTS, configFolder)
settings = deepcopy(DEFAULTS)
except Exception:
settings = deepcopy(DEFAULTS)
if check(settings) > 0: save(settings, configFolder) # Check the settings and save them if something changed
return settings