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
Catch-all raised by GitLabClient.list_files when listing a directory via the repository tree API fails with any error other than 404 (returns []), 403, or 401. The underlying exception (httpx.HTTPStatusError, network failure, JSON decode error) is embedded in the message.
Source
Thrown at litellm/integrations/gitlab/gitlab_client.py:230
files: Final[list[str]] = []
for item in data:
if item.get("type") == "blob":
file_path = item.get("path", "")
if not file_extension or file_path.endswith(file_extension):
files.append(file_path)
return files
except Exception as e:
status: Final = getattr(getattr(e, "response", None), "status_code", None)
if status == 404:
return []
if status == 403:
raise Exception(
f"Access denied to directory '{directory_path}'. Check your GitLab permissions for project '{self.project}'."
)
if status == 401:
raise Exception("Authentication failed. Check your GitLab token and auth_method.")
raise Exception(f"Failed to list files in '{directory_path}': {e}")
def get_repository_info(self) -> dict[str, Any]:
"""Get information about the project/repository."""
url: Final = f"{self.base_url}/projects/{self._project_enc}"
try:
resp: Final = self.http_handler.get(url, headers=self.headers)
resp.raise_for_status()
return resp.json()
except Exception as e:
raise Exception(f"Failed to get repository info: {e}")
def test_connection(self) -> bool:
"""Test the connection to the GitLab project."""
try:
self.get_repository_info()
return True
except Exception:
return FalseView on GitHub (pinned to 6c2dcb801b)
Solutions
- Read the embedded {e} to get the exact status/error
- For 5xx/timeout: check GitLab instance status and retry with backoff
- Validate base_url format (e.g. https://gitlab.com/api/v4, no trailing slash issues)
- For very large repos, list a narrower directory_path instead of recursive scans
Defensive patterns
Strategy: retry
Try / catch
try:
files = client.list_files(directory)
except Exception as e:
if "429" in str(e) or "5" in str(e):
backoff_and_retry()
else:
raise Prevention
- Prefer narrow directory_path over recursive full-repo scans
- Cache listing results between runs
- Monitor GitLab rate-limit headers
When it happens
Trigger: Calling list_files()/list_templates()/load_all_prompts() when GitLab returns 5xx or 429, the connection times out, pagination parameters are invalid, or the response body is not valid JSON (HTML error page from a misrouted base_url).
Common situations: Very large directories exceeding pagination limits handled incorrectly; self-hosted GitLab behind a load balancer returning 502; base_url including a trailing path that yields HTML; slow networks causing read timeouts during bulk prompt loading.
Related errors
- Failed to fetch file '{file_path}' via JSON endpoint: {e}
- Failed to get repository info: {e}
- Failed to get branches: {e}
- Failed to get file metadata for '{file_path}': {e}
- Error from qdrant checking if /collections exist {collection
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/cfaebbc4d6dc32d9.
Report an issue: GitHub.