{"id":"a28f4b378301d8e1","repo":"python-poetry/poetry","slug":"invalid-cache-key","errorCode":null,"errorMessage":"Invalid cache key","messagePattern":"Invalid cache key","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/poetry/console/commands/cache/clear.py","lineNumber":94,"sourceCode":"            raise RuntimeError(\n                \"Only specifying the package name is not yet supported. \"\n                \"Add a specific version to clear\"\n            )\n        elif len(parts) == 3:\n            package = canonicalize_name(parts[1])\n            version = parts[2]\n\n            if not cache.has(f\"{package}:{version}\"):\n                self.line(f\"No cache entries for {package}:{version}\")\n                return 0\n\n            delete = self.confirm(f\"Delete cache entry {package}:{version}\", True)\n            if not delete:\n                return 0\n\n            cache.forget(f\"{package}:{version}\")\n        else:\n            raise ValueError(\"Invalid cache key\")\n\n        return 0\n","sourceCodeStart":76,"sourceCodeEnd":97,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/console/commands/cache/clear.py#L76-L97","documentation":"Raises ValueError in CacheClearCommand.handle() when the cache argument has more than 3 colon-separated parts (root:package:version is the max). The else branch at line 93-94 catches any key with 4+ segments as invalid. This is a malformed-input guard on the cache key format.","triggerScenarios":"Running `poetry cache clear pypi:requests:2.28.0:extra` or any cache argument with more than 3 colon-separated parts.","commonSituations":"User appends extra segments by mistake, includes a colon in a package/version name, or misunderstands the expected key format.","solutions":["Use exactly the format root:package:version (3 parts) or root (1 part with --all).","Check for stray colons in the argument; quote the argument if package names contain colons."],"exampleFix":"# before (error)\npoetry cache clear pypi:requests:2.28.0:extra-segment\n# after\npoetry cache clear pypi:requests:2.28.0","handlingStrategy":"validation","validationCode":"def validate_cache_key_format(cache_arg: str) -> None:\n    parts = cache_arg.split(\":\") if cache_arg else []\n    if len(parts) > 3:\n        raise ValueError(f\"Cache key has {len(parts)} parts; maximum is 3 (root:package:version)\")","typeGuard":"def is_valid_cache_key_format(cache_arg: str) -> bool:\n    parts = cache_arg.split(\":\") if cache_arg else []\n    return len(parts) <= 3","tryCatchPattern":null,"preventionTips":["Limit the cache key to at most 3 colon-separated segments.","Check for stray colons in package or version names.","Quote the argument if it contains colons that are part of the data, not delimiters."],"tags":["cache-command","valueerror","invalid-format","cli-validation"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}