config: reject non-json-serialisable writes

see #4788
This commit is contained in:
SomberNight 2018-10-21 14:58:55 +02:00
parent ef2a6359e4
commit 6958c0ccc3
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
2 changed files with 7 additions and 1 deletions

View File

@ -140,6 +140,12 @@ class SimpleConfig(PrintError):
if not self.is_modifiable(key):
self.print_stderr("Warning: not changing config key '%s' set on the command line" % key)
return
try:
json.dumps(key)
json.dumps(value)
except:
self.print_error(f"json error: cannot save {repr(key)} ({repr(value)})")
return
self._set_key_in_user_config(key, value, save)
def _set_key_in_user_config(self, key, value, save=True):

View File

@ -90,7 +90,7 @@ class JsonDB(PrintError):
json.dumps(key, cls=util.MyEncoder)
json.dumps(value, cls=util.MyEncoder)
except:
self.print_error("json error: cannot save", key)
self.print_error(f"json error: cannot save {repr(key)} ({repr(value)})")
return
with self.db_lock:
if value is not None: