{"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/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/bitbucket/bitbucket_client.py#L192-L228","documentation":"Catch-all from BitBucketClient.get_branches: the GET to /2.0/repositories/{workspace}/{repo}/refs/branches failed with a non-2xx status or its JSON could not be parsed. Unlike list_files_in_directory, this method has no per-status branching — every failure becomes the same wrapped Exception. Note it returns only the first page of branches (data['values']) since no pagination is followed.","triggerScenarios":"Calling get_branches() with credentials lacking repository read scope, when the repository has no branches or was emptied, or when the workspace slug is wrong. Also triggered by any 5xx or network error since all exceptions collapse into this one message.","commonSituations":"Validating that a configured branch exists before pointing the client at it; newly created empty repositories; tokens scoped to a single branch via branch restrictions.","solutions":["Confirm credentials and slugs with get_repository_info()/test_connection() before calling get_branches()","Extract the status from the message: 404 usually means wrong workspace/repo slug","If you need all branches in a large repo, page through pagelen/next links yourself — this client only returns page one","Retry on transient 5xx with backoff"],"exampleFix":"# before\nbranches = client.get_branches()\n\n# after\nif not client.test_connection():\n    raise RuntimeError(\"BitBucket connection failed; check config\")\nbranches = client.get_branches()\nbranch_names = [b[\"name\"] for b in branches]","handlingStrategy":"try-catch","validationCode":"if not client.test_connection():\n    raise RuntimeError(\"Cannot list branches: BitBucket connection failed\")","typeGuard":null,"tryCatchPattern":"try:\n    branches = client.get_branches()\nexcept Exception as e:\n    if \"404\" in str(e):\n        branches = []  # wrong slug or empty repo\n    else:\n        raise","preventionTips":["Validate slugs with get_repository_info() first","Remember this returns only the first page of branches","Treat branch listing as advisory, not critical-path"],"tags":["bitbucket","branches","api-client"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}