{"record":{"id":"cfaebbc4d6dc32d9","repo":"BerriAI/litellm","slug":"failed-to-list-files-in-directory-path-e-cfaebb","errorCode":null,"errorMessage":"Failed to list files in '{directory_path}': {e}","messagePattern":"Failed to list files in '(.+?)': (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/gitlab/gitlab_client.py","lineNumber":230,"sourceCode":"            files: Final[list[str]] = []\n            for item in data:\n                if item.get(\"type\") == \"blob\":\n                    file_path = item.get(\"path\", \"\")\n                    if not file_extension or file_path.endswith(file_extension):\n                        files.append(file_path)\n            return files\n\n        except Exception as e:\n            status: Final = getattr(getattr(e, \"response\", None), \"status_code\", None)\n            if status == 404:\n                return []\n            if status == 403:\n                raise Exception(\n                    f\"Access denied to directory '{directory_path}'. Check your GitLab permissions for project '{self.project}'.\"\n                )\n            if status == 401:\n                raise Exception(\"Authentication failed. Check your GitLab token and auth_method.\")\n            raise Exception(f\"Failed to list files in '{directory_path}': {e}\")\n\n    def get_repository_info(self) -> dict[str, Any]:\n        \"\"\"Get information about the project/repository.\"\"\"\n        url: Final = f\"{self.base_url}/projects/{self._project_enc}\"\n        try:\n            resp: Final = self.http_handler.get(url, headers=self.headers)\n            resp.raise_for_status()\n            return resp.json()\n        except Exception as e:\n            raise Exception(f\"Failed to get repository info: {e}\")\n\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","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/gitlab/gitlab_client.py#L212-L248","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    files = client.list_files(directory)\nexcept Exception as e:\n    if \"429\" in str(e) or \"5\" in str(e):\n        backoff_and_retry()\n    else:\n        raise","preventionTips":["Prefer narrow directory_path over recursive full-repo scans","Cache listing results between runs","Monitor GitLab rate-limit headers"],"tags":["gitlab","http","network","api-client"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}