From c599a41b84b48566c8510c603ec1cd974f6ee9de Mon Sep 17 00:00:00 2001 From: sprmn24 Date: Sat, 25 Apr 2026 01:05:25 +0300 Subject: [PATCH] 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. --- hermes_cli/auth.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hermes_cli/auth.py b/hermes_cli/auth.py index 0a472f2d8..00685436d 100644 --- a/hermes_cli/auth.py +++ b/hermes_cli/auth.py @@ -743,7 +743,18 @@ def _load_auth_store(auth_file: Optional[Path] = None) -> Dict[str, Any]: try: raw = json.loads(auth_file.read_text()) - except Exception: + except Exception as exc: + corrupt_path = auth_file.with_suffix(".json.corrupt") + try: + import shutil + shutil.copy2(auth_file, corrupt_path) + 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": {}} if isinstance(raw, dict) and (