BerriAI/litellm · error · Exception

Failed to get branches

Error message

Failed to get branches: {e}

What it means

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.

Solutions

  1. Run test_connection() first — if it returns False, fix auth/workspace/repo before debugging branches
  2. Confirm the branch name and repo slugs with: curl -H "Authorization: Bearer $TOKEN" "https://api.bitbucket.org/2.0/repositories/<ws>/<repo>/refs/branches"
  3. Check whether the token was rotated or expired and update the config
  4. Retry with backoff if the wrapped cause indicates 429/5xx
Defensive patterns

Strategy: try-catch

Validate before calling

if not client.test_connection():
    raise RuntimeError("fix auth/repo config before listing branches")

Try / catch

try:
    branches = client.get_branches()
except Exception as e:
    # everything (404/401/403/network) lands here; test_connection() disambiguates auth vs repo
    raise

Prevention

When it happens

Trigger: 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 [].

Common situations: 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.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/f8ba39bdbdae2ee9. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/bitbucket/bitbucket_client.py:210

            return False

    def get_branches(self) -> list[dict[str, Any]]:
        """
        Get list of branches in the repository.

        Returns:
            List of branch information dictionaries
        """
        url: Final = f"{self.base_url}/repositories/{self.workspace}/{self.repository}/refs/branches"

        try:
            response: Final = self.http_handler.get(url, headers=self.headers)
            response.raise_for_status()

            data: Final = response.json()
            return data.get("values", [])
        except Exception as e:
            raise Exception(f"Failed to get branches: {e}")

    def get_file_metadata(self, file_path: str) -> dict[str, Any] | None:
        """
        Get metadata about a file (size, last modified, etc.).

        Args:
            file_path: Path to the file in the repository

        Returns:
            Dictionary containing file metadata, or None if file not found
        """
        safe_path: Final = _sanitize_file_path(file_path)
        url: Final = f"{self.base_url}/repositories/{self.workspace}/{self.repository}/src/{self.branch}/{safe_path}"

        try:
            # Use GET with Range header to get just the headers (HEAD equivalent)
            headers: Final = self.headers.copy()
            headers["Range"] = "bytes=0-0"  # Request only first byte to get headers

View on GitHub (pinned to 77b7c6c40c)