fix(auth): preserve corrupt auth.json and warn instead of silently resetting

_load_auth_store() caught all parse/read exceptions and silently
returned an empty store, making corruption look like a logout with
no diagnostic information and no way to recover the original file.

Now copies the corrupt file to auth.json.corrupt before resetting,
and logs a warning with the exception and backup path.
This commit is contained in:
sprmn24 2026-04-25 01:05:25 +03:00 committed by Teknium
parent c7d62b3fe3
commit c599a41b84

View file

@ -743,7 +743,18 @@ def _load_auth_store(auth_file: Optional[Path] = None) -> Dict[str, Any]:
try: try:
raw = json.loads(auth_file.read_text()) raw = json.loads(auth_file.read_text())
except Exception as exc:
corrupt_path = auth_file.with_suffix(".json.corrupt")
try:
import shutil
shutil.copy2(auth_file, corrupt_path)
except Exception: except Exception:
pass
logger.warning(
"auth: failed to parse %s (%s) — starting with empty store. "
"Corrupt file preserved at %s",
auth_file, exc, corrupt_path,
)
return {"version": AUTH_STORE_VERSION, "providers": {}} return {"version": AUTH_STORE_VERSION, "providers": {}}
if isinstance(raw, dict) and ( if isinstance(raw, dict) and (