{"record":{"id":"89442dbc7d54e8f0","repo":"langchain-ai/deepagents","slug":"failed-to-parse-credential-file-path-exc-del","errorCode":null,"errorMessage":"Failed to parse credential file {path}: {exc}. Delete the file and re-add credentials via /auth if it is corrupt.","messagePattern":"Failed to parse credential file (.+?): (.+?)\\. Delete the file and re-add credentials via /auth if it is corrupt\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/auth_store.py","lineNumber":189,"sourceCode":"        data = json.loads(raw)\n    except FileNotFoundError:\n        return None\n    except OSError as exc:\n        msg = (\n            f\"Failed to read credential file {path}: {exc}. \"\n            \"Check the file permissions on the parent directory.\"\n        )\n        raise RuntimeError(msg) from exc\n    except (UnicodeDecodeError, json.JSONDecodeError) as exc:\n        # `UnicodeDecodeError` (a `ValueError`, not an `OSError`) escapes the\n        # handler above when the file holds non-UTF-8 bytes; treat a decode\n        # failure as corruption so callers get the same `RuntimeError` hint\n        # instead of an unhandled traceback.\n        msg = (\n            f\"Failed to parse credential file {path}: {exc}. \"\n            \"Delete the file and re-add credentials via /auth if it is corrupt.\"\n        )\n        raise RuntimeError(msg) from exc\n    if not isinstance(data, dict):\n        msg = (\n            f\"Credential file {path} is not a JSON object. \"\n            \"Delete it and re-add credentials via /auth.\"\n        )\n        # `RuntimeError` (not `TypeError`) is intentional: every corruption\n        # path here surfaces the same error class so callers can render one\n        # remediation hint regardless of the specific shape problem.\n        raise RuntimeError(msg)  # noqa: TRY004\n    version = data.get(\"version\")\n    if version != _STORAGE_VERSION:\n        msg = (\n            f\"Credential file {path} has unsupported version {version!r} \"\n            f\"(expected {_STORAGE_VERSION}). Delete it and re-add credentials via \"\n            \"/auth.\"\n        )\n        raise RuntimeError(msg)\n    return data","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/auth_store.py#L171-L207","documentation":"Raised by `_read_raw` in auth_store.py when the on-disk credential file exists but cannot be parsed as JSON. The library treats any parse failure as file corruption and surfaces it as a single `RuntimeError` (chained from the original exception) so callers can show one consistent remediation hint instead of an unhandled traceback. Every caller (load_credentials, set_stored_key, delete_stored_key) funnels through this reader.","triggerScenarios":"Calling load_credentials(), set_stored_key(), or delete_stored_key() when the credential file at auth_path() contains invalid JSON — e.g. truncated content, a partial write, manual editing mistakes, or binary garbage.","commonSituations":"The user hand-edited the credentials file and broke JSON syntax; the process was killed mid-write (crash/power loss before atomic rename completes); disk-full truncated the file; another tool overwrote the file with a non-JSON format.","solutions":["Delete the credential file returned by auth_path() and re-add credentials via the /auth command (or set_stored_key).","Inspect the file to confirm corruption (e.g. `python -m json.tool <path>`) before deleting, in case the content is recoverable.","Check for a backup or copy the file aside first if the keys are hard to re-obtain.","Verify the parent directory and disk are writable so the replacement write succeeds."],"exampleFix":"// before: raw json.load blow-up on corrupt file\ncreds = json.loads(open(path).read())\n// after: recover by resetting the store\ntry:\n    creds = load_credentials()\nexcept RuntimeError:\n    pathlib.Path(auth_path()).unlink(missing_ok=True)\n    creds = {}","handlingStrategy":"try-catch","validationCode":"// pre-check parseability before calling the API\ndef _cred_file_is_valid() -> bool:\n    p = pathlib.Path(auth_path())\n    if not p.exists():\n        return True\n    try:\n        json.loads(p.read_text())\n        return True\n    except (json.JSONDecodeError, OSError):\n        return False","typeGuard":"def _is_dict(data: object) -> TypeGuard[dict]:\n    return isinstance(data, dict)","tryCatchPattern":"try:\n    creds = load_credentials()\nexcept RuntimeError as exc:\n    logger.warning(\"credential store unreadable, resetting: %s\", exc)\n    pathlib.Path(auth_path()).unlink(missing_ok=True)\n    creds = {}","preventionTips":["Never hand-edit the credential file; always use /auth or set_stored_key.","Avoid killing the process during credential writes (the library writes atomically, but mid-write kills still risk truncation on some filesystems).","Monitor disk space on the volume holding the state directory.","Keep a backup of the credential file before running tools that touch it."],"tags":["auth","file-corruption","json","local-storage"],"backgroundTag":"credential-file-corrupt","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}