{"record":{"id":"f8ba39bdbdae2ee9","repo":"BerriAI/litellm","slug":"failed-to-get-branches-e","errorCode":null,"errorMessage":"Failed to get branches: {e}","messagePattern":"Failed to get branches: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/bitbucket/bitbucket_client.py","lineNumber":210,"sourceCode":"            return False\n\n    def get_branches(self) -> list[dict[str, Any]]:\n        \"\"\"\n        Get list of branches in the repository.\n\n        Returns:\n            List of branch information dictionaries\n        \"\"\"\n        url: Final = f\"{self.base_url}/repositories/{self.workspace}/{self.repository}/refs/branches\"\n\n        try:\n            response: Final = self.http_handler.get(url, headers=self.headers)\n            response.raise_for_status()\n\n            data: Final = response.json()\n            return data.get(\"values\", [])\n        except Exception as e:\n            raise Exception(f\"Failed to get branches: {e}\")\n\n    def get_file_metadata(self, file_path: str) -> dict[str, Any] | None:\n        \"\"\"\n        Get metadata about a file (size, last modified, etc.).\n\n        Args:\n            file_path: Path to the file in the repository\n\n        Returns:\n            Dictionary containing file metadata, or None if file not found\n        \"\"\"\n        safe_path: Final = _sanitize_file_path(file_path)\n        url: Final = f\"{self.base_url}/repositories/{self.workspace}/{self.repository}/src/{self.branch}/{safe_path}\"\n\n        try:\n            # Use GET with Range header to get just the headers (HEAD equivalent)\n            headers: Final = self.headers.copy()\n            headers[\"Range\"] = \"bytes=0-0\"  # Request only first byte to get headers","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/bitbucket/bitbucket_client.py#L192-L228","documentation":"Raised by BitBucketClient.get_branches when any exception occurs during GET /repositories/{workspace}/{repository}/refs/branches. Like get_repository_info, it wraps everything into one message: HTTP status errors (404 wrong repo, 401 bad token, 403 no permission, 429 rate limit), network failures, and JSON decode errors all surface identically.","triggerScenarios":"Calling get_branches against a repository slug that does not exist, with an expired/revoked token, with a token lacking read access to refs, or when the response body is not valid JSON (proxy interference). A 200 response missing the 'values' key is NOT an error — it returns [].","commonSituations":"Verifying branch configuration (e.g. checking that the configured 'branch' actually exists) in setup scripts; token rotation; wrong workspace id; API rate limiting during bulk prompt syncs.","solutions":["Run test_connection() first — if it returns False, fix auth/workspace/repo before debugging branches","Confirm the branch name and repo slugs with: curl -H \"Authorization: Bearer $TOKEN\" \"https://api.bitbucket.org/2.0/repositories/<ws>/<repo>/refs/branches\"","Check whether the token was rotated or expired and update the config","Retry with backoff if the wrapped cause indicates 429/5xx"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if not client.test_connection():\n    raise RuntimeError(\"fix auth/repo config before listing branches\")","typeGuard":null,"tryCatchPattern":"try:\n    branches = client.get_branches()\nexcept Exception as e:\n    # everything (404/401/403/network) lands here; test_connection() disambiguates auth vs repo\n    raise","preventionTips":["Validate auth with test_connection() before calling branch APIs","Cache the branch list and refresh periodically instead of calling per-request","Alert on this error to distinguish config drift (renamed repo, rotated token) from outages"],"tags":["bitbucket","http","branches","authentication"],"backgroundTag":"http-request-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}