{"record":{"id":"90f956edb69036fc","repo":"xtekky/gpt4free","slug":"failed-to-read-oauth-credentials-from-path-e","errorCode":null,"errorMessage":"Failed to read OAuth credentials from {path}: {e}","messagePattern":"Failed to read OAuth credentials from (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/Antigravity.py","lineNumber":408,"sourceCode":"        now = time.time()\n        if cached:\n            expires_at = cached[\"expiry_date\"] / 1000  # ms to seconds\n            if expires_at - now > self.TOKEN_BUFFER_TIME:\n                self._access_token = cached[\"access_token\"]\n                self._expiry = expires_at\n                return  # Use cached token if valid\n\n        # Try loading from cache file or default path\n        path = AntigravityAuthManager.get_cache_file()\n        if not path.exists():\n            path = get_antigravity_oauth_creds_path()\n\n        if path.exists():\n            try:\n                with path.open(\"r\") as f:\n                    creds = json.load(f)\n            except Exception as e:\n                raise RuntimeError(f\"Failed to read OAuth credentials from {path}: {e}\")\n        else:\n            # Parse credentials from environment\n            if \"ANTIGRAVITY_SERVICE_ACCOUNT\" not in self.env:\n                raise RuntimeError(\n                    \"ANTIGRAVITY_SERVICE_ACCOUNT environment variable not set. \"\n                    f\"Please set it or create credentials at {get_antigravity_oauth_creds_path()}\"\n                )\n            creds = json.loads(self.env[\"ANTIGRAVITY_SERVICE_ACCOUNT\"])\n\n        # Store project_id from credentials if available\n        if creds.get(\"project_id\"):\n            self._project_id = creds[\"project_id\"]\n\n        refresh_token = creds.get(\"refresh_token\")\n        access_token = creds.get(\"access_token\")\n        expiry_date = creds.get(\"expiry_date\")  # milliseconds since epoch\n\n        # Use original access token if still valid","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/Antigravity.py#L390-L426","documentation":"RuntimeError raised while loading Antigravity OAuth credentials from disk: a credentials file exists (either the auth-manager cache or the default path from get_antigravity_oauth_creds_path()), but opening/parsing it raised — json.load failing on malformed JSON is the usual cause, hence the {e} chaining json.JSONDecodeError. The {path} in the message names the exact file that failed.","triggerScenarios":"The cached/default credentials JSON is truncated (process killed mid-write), hand-edited and made invalid (trailing commas, comments, smart quotes), empty (0 bytes), or not JSON at all (e.g. a HTML error page saved there by mistake); unreadable encoding can also raise here.","commonSituations":"Crash during token cache write leaving a partial file; users pasting credentials with formatting damage; tools writing logs into the creds path; the cache file being from an incompatible older schema that no longer parses.","solutions":["Validate the file named in the message: python -m json.tool <path> — it must be valid JSON.","If corrupt, delete (or move aside) the cache file and the default creds file; the flow will fall back to the service-account env var or a fresh interactive login.","If the JSON is valid but the error persists, check {e} for permission/encoding issues (file readable, UTF-8)."],"exampleFix":"# before (truncated/corrupt cache keeps failing)\n# ~/.cache/antigravity/oauth_creds.json  ->  {\"refresh_token\": \"ya29.\"\n\n# after\nrm ~/.cache/antigravity/oauth_creds.json  # then re-run auth to regenerate","handlingStrategy":"validation","validationCode":"import json, pathlib\npath = pathlib.Path(creds_path)\nif path.exists():\n    try:\n        json.loads(path.read_text())\n    except json.JSONDecodeError as e:\n        raise SystemExit(f'Corrupt Antigravity creds at {path}: delete it and re-auth ({e})')","typeGuard":null,"tryCatchPattern":"try:\n    ...\nexcept RuntimeError as e:\n    if 'Failed to read OAuth credentials' in str(e):\n        creds_path.unlink(missing_ok=True)  # drop corrupt cache, re-run auth flow\n        ...","preventionTips":["Validate credential JSON with json.tool after any manual edit.","Write credential caches atomically (tmp file + rename) in your own code.","Delete and regenerate rather than hand-repairing corrupt token files."],"tags":["oauth","antigravity","json","credentials","cache"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}