{"record":{"id":"66d83357b6b3f716","repo":"BerriAI/litellm","slug":"failed-to-get-branches-e-66d833","errorCode":null,"errorMessage":"Failed to get branches: {e}","messagePattern":"Failed to get branches: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/gitlab/gitlab_client.py","lineNumber":259,"sourceCode":"\n    def test_connection(self) -> bool:\n        \"\"\"Test the connection to the GitLab project.\"\"\"\n        try:\n            self.get_repository_info()\n            return True\n        except Exception:\n            return False\n\n    def get_branches(self) -> list[dict[str, Any]]:\n        \"\"\"Get list of branches in the repository.\"\"\"\n        url: Final = f\"{self.base_url}/projects/{self._project_enc}/repository/branches\"\n        try:\n            resp: Final = self.http_handler.get(url, headers=self.headers)\n            resp.raise_for_status()\n            data: Final = resp.json()\n            return data if isinstance(data, list) else []\n        except Exception as e:\n            raise Exception(f\"Failed to get branches: {e}\")\n\n    def get_file_metadata(self, file_path: str, *, ref: str | None = None) -> dict[str, Any] | None:\n        \"\"\"\n        Get minimal metadata about a file via RAW endpoint headers at a given ref.\n\n        Args:\n            file_path: Path to the file in the repository.\n            ref: Optional override (tag/branch/SHA). Defaults to self.ref.\n        \"\"\"\n        url: Final = self._file_raw_url(file_path, ref=ref)\n        try:\n            headers: Final = dict(self.headers)\n            headers[\"Range\"] = \"bytes=0-0\"\n            resp: Final = self.http_handler.get(url, headers=headers)\n            if resp.status_code == 404:\n                return None\n            resp.raise_for_status()\n            return {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/gitlab/gitlab_client.py#L241-L277","documentation":"Catch-all raised by GitLabClient.get_branches when GET /projects/{id}/repository/branches fails. Any HTTP or network error is wrapped; a 200 response with a non-list body is silently coerced to [] instead. The original error is embedded in the message.","triggerScenarios":"Calling get_branches() with an invalid/insufficient token (401/403), a project with repositories disabled (404 or error payload), rate limiting, or connectivity problems to the GitLab API.","commonSituations":"Token lacks read_repository scope; project is an empty repo or has the repository feature disabled; paginated responses expected but endpoint blocked; self-hosted instance maintenance window.","solutions":["Read the embedded {e} for the HTTP status","Verify token scopes and project permissions with the projects endpoint first","Retry transient 5xx/429 with backoff","Confirm the repository exists and has branches in the GitLab UI"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    branches = client.get_branches()\nexcept Exception as e:\n    if \"404\" in str(e):\n        branches = []  # repo may not exist yet / empty\n    else:\n        raise","preventionTips":["Check repo existence before branch listing","Treat branch listing as optional metadata, not a hard dependency"],"tags":["gitlab","http","api-client","branches"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}