{"id":"2c5825c142c5048a","repo":"python-poetry/poetry","slug":"add-the-all-option-if-you-want-to-clear-all-cach","errorCode":null,"errorMessage":"Add the --all option if you want to clear all cache entries","messagePattern":"Add the --all option if you want to clear all cache entries","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"warning","filePath":"src/poetry/console/commands/cache/clear.py","lineNumber":55,"sourceCode":"            parts = cache.split(\":\")\n            root = parts[0]\n        else:\n            parts = []\n            root = \"\"\n\n        config = Config.create()\n        cache_dir = config.repository_cache_directory / root\n\n        try:\n            cache_dir.relative_to(config.repository_cache_directory)\n        except ValueError:\n            raise ValueError(f\"{root} is not a valid repository cache\")\n\n        cache = FileCache(cache_dir)\n\n        if len(parts) < 2:\n            if not self.option(\"all\"):\n                raise RuntimeError(\n                    \"Add the --all option if you want to clear all cache entries\"\n                )\n\n            if not cache_dir.exists():\n                self.line(\n                    f\"No cache entries for {root}\" if root else \"No cache entries\"\n                )\n                return 0\n\n            # Calculate number of entries\n            entries_count = sum(\n                len(files) for _path, _dirs, files in os.walk(str(cache_dir))\n            )\n\n            delete = self.confirm(f\"<question>Delete {entries_count} entries?</>\", True)\n            if not delete:\n                return 0\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/console/commands/cache/clear.py#L37-L73","documentation":"Raises RuntimeError in CacheClearCommand.handle() when the user provides only a root cache name (fewer than 2 colon-separated parts) without the --all flag. Poetry requires --all to clear an entire cache root because that is a bulk, potentially destructive operation. The check at line 53-57 is `if len(parts) < 2 and not self.option('all')`.","triggerScenarios":"Running `poetry cache clear pypi` (just a root, no package:version) without --all. The cache argument splits into 1 part, which triggers the guard.","commonSituations":"User wants to clear all of a specific cache and forgets --all, or expects `poetry cache clear pypi` to work without a flag.","solutions":["Add --all: `poetry cache clear pypi --all`.","If you want to clear a specific entry, specify package and version: `poetry cache clear pypi:requests:2.28.0`."],"exampleFix":"# before (error)\npoetry cache clear pypi\n# after\npoetry cache clear pypi --all","handlingStrategy":"validation","validationCode":"def validate_cache_clear(cache_arg: str, all_flag: bool) -> None:\n    parts = cache_arg.split(\":\") if cache_arg else []\n    if len(parts) < 2 and not all_flag:\n        raise ValueError(\"Add --all to clear an entire cache root\")","typeGuard":"def needs_all_flag(cache_arg: str, all_flag: bool) -> bool:\n    parts = cache_arg.split(\":\") if cache_arg else []\n    return len(parts) < 2 and not all_flag","tryCatchPattern":null,"preventionTips":["Always pass --all when clearing a whole cache root (e.g. 'poetry cache clear pypi --all').","Specify package:version for targeted clearing: 'poetry cache clear pypi:pkg:1.0.0'.","Remember the cache key format: root[:package[:version]]."],"tags":["cache-command","runtimeerror","cli-validation","safety-guard"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}