BerriAI/litellm · error · Exception
Failed to list files in '{directory_path}': {e}
Error message
Failed to list files in '{directory_path}': {e} What it means
Raised by BitBucketClient.list_files_in_directory when the BitBucket src endpoint returns any HTTP status other than 401/403/404 (e.g. 500, 502, 429 rate-limit). The original requests exception is stringified into the message, so the status code and URL are visible in text but the exception type and response object are lost. It is a catch-all re-raise after the specific status codes were already handled.
Source
Thrown at litellm/integrations/bitbucket/bitbucket_client.py:161
file_path = item.get("path", "")
if file_path.endswith(file_extension):
files.append(file_path)
return files
except Exception as e:
# Check if it's an HTTP error
if hasattr(e, "response") and hasattr(e.response, "status_code"):
if e.response.status_code == 404:
return []
elif e.response.status_code == 403:
raise Exception(
f"Access denied to directory '{directory_path}'. Check your BitBucket permissions for workspace '{self.workspace}' and repository '{self.repository}'."
)
elif e.response.status_code == 401:
raise Exception("Authentication failed. Check your BitBucket access token and permissions.")
else:
raise Exception(f"Failed to list files in '{directory_path}': {e}")
else:
raise Exception(f"Error listing files in '{directory_path}': {e}")
def get_repository_info(self) -> dict[str, Any]:
"""
Get information about the repository.
Returns:
Dictionary containing repository information
"""
url: Final = f"{self.base_url}/repositories/{self.workspace}/{self.repository}"
try:
response: Final = self.http_handler.get(url, headers=self.headers)
response.raise_for_status()
return response.json()
except Exception as e:
raise Exception(f"Failed to get repository info: {e}")View on GitHub (pinned to 6c2dcb801b)
Solutions
- Read the embedded status code in the message text; for 429 add backoff/retry with exponential delays around list_files_in_directory
- Cache directory listings instead of listing on every prompt lookup
- If pointing at BitBucket Server/Data Center, verify base_url includes the /rest/api/2.0-style path your instance expects
- Check https://status.atlassian.com for active BitBucket Cloud incidents if the status is 5xx
Example fix
# before
files = client.list_files_in_directory("prompts")
# after (retry with backoff)
import time
for attempt in range(5):
try:
files = client.list_files_in_directory("prompts")
break
except Exception as e:
if "429" in str(e) and attempt < 4:
time.sleep(2 ** attempt)
continue
raise Defensive patterns
Strategy: retry
Try / catch
import time
for attempt in range(5):
try:
files = client.list_files_in_directory("prompts")
break
except Exception as e:
msg = str(e)
if ("429" in msg or "5" in msg.split(" ")[0]) and attempt < 4:
time.sleep(2 ** attempt)
continue
raise Prevention
- Cache directory listings with a TTL instead of listing per request
- Stay under BitBucket Cloud's anonymous/authenticated rate limits by batching work
- Log the full message — it embeds the HTTP status for triage
When it happens
Trigger: BitBucket API rate limiting (429) from aggressive polling of list_files_in_directory, BitBucket server errors (5xx), a branch name that triggers a redirect, or a workspace/repository name with typos producing unexpected 4xx codes not in the handled set.
Common situations: Prompt-manager loops that list a prompts directory on every request and hit rate limits; BitBucket Cloud incidents; enterprise BitBucket Server deployments where the API path shape differs and base_url was overridden.
Related errors
- Failed to fetch file '{file_path}': {e}
- BedrockException: Rate Limit Error - {error_str}
- Project tpm_limit ({data.tpm_limit}) exceeds team's tpm_limi
- Project rpm_limit ({data.rpm_limit}) exceeds team's rpm_limi
- bitbucket_config is required for BitBucket prompt integratio
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/af106d4bd8fa1a6f.
Report an issue: GitHub.