{"record":{"id":"a316aae38efe4588","repo":"BerriAI/litellm","slug":"ref-must-be-a-non-empty-string","errorCode":null,"errorMessage":"ref must be a non-empty string","messagePattern":"ref must be a non-empty string","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/gitlab/gitlab_client.py","lineNumber":108,"sourceCode":"        self,\n        directory_path: str = \"\",\n        recursive: bool = False,\n        *,\n        ref: str | None = None,\n    ) -> str:\n        path_q: Final = f\"&path={quote(directory_path, safe='')}\" if directory_path else \"\"\n        rec_q: Final = \"&recursive=true\" if recursive else \"\"\n        ref_q: Final = quote(ref or self.ref, safe=\"\")\n        return f\"{self.base_url}/projects/{self._project_enc}/repository/tree?ref={ref_q}{path_q}{rec_q}\"\n\n    # ------------------------\n    # Public API\n    # ------------------------\n\n    def set_ref(self, ref: str) -> None:\n        \"\"\"Override the default ref (tag/branch) for subsequent calls.\"\"\"\n        if not ref:\n            raise ValueError(\"ref must be a non-empty string\")\n        self.ref = ref\n\n    def get_file_content(self, file_path: str, *, ref: str | None = None) -> str | None:\n        \"\"\"\n        Fetch the content of a file from the GitLab repository at the given ref\n        (tag, branch, or commit SHA). If `ref` is None, uses self.ref.\n\n        Strategy:\n          1) Try the RAW endpoint (returns bytes of the file)\n          2) Fallback to the JSON endpoint (returns base64-encoded content)\n\n        Returns:\n            File content as UTF-8 string, or None if file not found.\n        \"\"\"\n        raw_url: Final = self._file_raw_url(file_path, ref=ref)\n\n        try:\n            resp: Final = self.http_handler.get(raw_url, headers=self.headers)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/gitlab/gitlab_client.py#L90-L126","documentation":"GitLabClient.set_ref replaces the default ref (tag or branch) used by all subsequent GitLab API calls; it rejects falsy arguments, so passing '' or None raises immediately. This is a local config-plumbing error raised before anything is sent over the network.","triggerScenarios":"set_ref(os.getenv('GITLAB_REF')) with the variable unset (None); set_ref('') from a config default; a computed ref like `tag or branch` that evaluated to an empty string; calling set_ref unconditionally for an 'optional' override.","commonSituations":"Optional per-prompt ref overrides wired from config that are usually absent; refs derived from release variables that are empty outside CI; mixing None-vs-'' conventions across config layers.","solutions":["Only call set_ref when you actually have a non-empty ref","Default the override to a concrete branch (e.g. 'main') instead of '' or None","Normalize first: ref = (ref or '').strip(), then guard before calling"],"exampleFix":"# before\nclient.set_ref(git_ref)  # git_ref may be None or \"\"\n\n# after\nif git_ref and git_ref.strip():\n    client.set_ref(git_ref.strip())","handlingStrategy":"validation","validationCode":"def normalize_ref(ref: str | None) -> str | None:\n    \"\"\"Return a clean ref or None; call set_ref only when not None.\"\"\"\n    cleaned = (ref or \"\").strip()\n    return cleaned or None\n\n\nclean_ref = normalize_ref(git_ref)\nif clean_ref:\n    client.set_ref(clean_ref)","typeGuard":"def is_valid_ref(ref: object) -> bool:\n    \"\"\"True when ref is a non-empty, non-whitespace string.\"\"\"\n    return isinstance(ref, str) and bool(ref.strip())","tryCatchPattern":"try:\n    client.set_ref(ref)\nexcept ValueError as e:\n    if \"ref must be a non-empty string\" in str(e):\n        raise RuntimeError(f\"invalid git ref configured: {ref!r}\") from e\n    raise","preventionTips":["Treat ref overrides as optional: guard every set_ref call","Validate refs (branch/tag/SHA strings) against your config schema","Prefer concrete defaults over empty strings for optional values"],"tags":["gitlab","ref","invalid-argument","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}