Răsfoiți Sursa

Show a clean error message when config.json has invalid JSON

ZiB 4 luni în urmă
părinte
comite
5febe60926
1 a modificat fișierele cu 4 adăugiri și 1 ștergeri
  1. 4 1
      room_cal/_utils.py

+ 4 - 1
room_cal/_utils.py

@@ -435,7 +435,10 @@ def get_config() -> Config:
   override_path = data_home() / 'config.json'
   if not override_path.exists():
     return Config.from_dict(default)
-  override = json.loads(override_path.read_text(encoding='utf-8'))
+  try:
+    override = json.loads(override_path.read_text(encoding='utf-8'))
+  except json.JSONDecodeError as e:
+    raise SystemExit(f"config.json parse error: {e}") from None
   return Config.from_dict(_deep_merge(default, override))