BerriAI/litellm · error · Exception
Failed to get branches: {e}
Error message
Failed to get branches: {e} What it means
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.
Source
Thrown at litellm/integrations/gitlab/gitlab_client.py:259
def test_connection(self) -> bool:
"""Test the connection to the GitLab project."""
try:
self.get_repository_info()
return True
except Exception:
return False
def get_branches(self) -> list[dict[str, Any]]:
"""Get list of branches in the repository."""
url: Final = f"{self.base_url}/projects/{self._project_enc}/repository/branches"
try:
resp: Final = self.http_handler.get(url, headers=self.headers)
resp.raise_for_status()
data: Final = resp.json()
return data if isinstance(data, list) else []
except Exception as e:
raise Exception(f"Failed to get branches: {e}")
def get_file_metadata(self, file_path: str, *, ref: str | None = None) -> dict[str, Any] | None:
"""
Get minimal metadata about a file via RAW endpoint headers at a given ref.
Args:
file_path: Path to the file in the repository.
ref: Optional override (tag/branch/SHA). Defaults to self.ref.
"""
url: Final = self._file_raw_url(file_path, ref=ref)
try:
headers: Final = dict(self.headers)
headers["Range"] = "bytes=0-0"
resp: Final = self.http_handler.get(url, headers=headers)
if resp.status_code == 404:
return None
resp.raise_for_status()
return {View on GitHub (pinned to 6c2dcb801b)
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
Defensive patterns
Strategy: try-catch
Try / catch
try:
branches = client.get_branches()
except Exception as e:
if "404" in str(e):
branches = [] # repo may not exist yet / empty
else:
raise Prevention
- Check repo existence before branch listing
- Treat branch listing as optional metadata, not a hard dependency
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to fetch file '{file_path}' via JSON endpoint: {e}
- Failed to list files in '{directory_path}': {e}
- Failed to get repository info: {e}
- Failed to get file metadata for '{file_path}': {e}
- Failed to get branches: {e}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/66d83357b6b3f716.
Report an issue: GitHub.