{"id":"c42d89e65d77d7e7","repo":"python-poetry/poetry","slug":"you-cannot-remove-the-repositories-section","errorCode":null,"errorMessage":"You cannot remove the [repositories] section","messagePattern":"You cannot remove the \\[repositories\\] section","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/poetry/console/commands/config.py","lineNumber":236,"sourceCode":"        values: list[str] = self.argument(\"value\")\n\n        if setting_key in self.unique_config_values:\n            if self.option(\"unset\"):\n                config.config_source.remove_property(setting_key)\n                return 0\n\n            return self._handle_single_value(\n                config.config_source,\n                setting_key,\n                self.unique_config_values[setting_key],\n                values,\n            )\n\n        # handle repositories\n        m = re.match(repo_regex, self.argument(\"key\"))\n        if m:\n            if not m.group(1):\n                raise ValueError(\"You cannot remove the [repositories] section\")\n\n            repo_name = m.group(1)\n\n            if self.option(\"unset\"):\n                repo = config.get([\"repositories\", repo_name])\n                if repo is None:\n                    raise ValueError(f\"There is no {repo_name} repository defined\")\n\n                if m.group(2):\n                    # Unset a specific sub-property\n                    config.config_source.remove_property(\n                        [\"repositories\", repo_name, m.group(2)]\n                    )\n                else:\n                    config.config_source.remove_property([\"repositories\", repo_name])\n\n                return 0\n","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/console/commands/config.py#L218-L254","documentation":"Raises ValueError in ConfigCommand.handle() when the user tries to unset the entire [repositories] section rather than a specific repository. The repo_regex matches group(1) as None (no repository name specified), and the check at line 235-236 blocks removal of the whole section to prevent accidental loss of all configured repositories.","triggerScenarios":"Running `poetry config repositories --unset` or `poetry config repo --unset` — the repo_regex matches but group(1) is empty/None.","commonSituations":"User intends to remove one repository but forgets the name, or attempts a bulk unset of all repositories.","solutions":["Specify the individual repository to unset: `poetry config repositories.myrepo --unset`.","Unset each repository individually if you need to remove all of them."],"exampleFix":"# before (error)\npoetry config repositories --unset\n# after\npoetry config repositories.myrepo --unset","handlingStrategy":"validation","validationCode":"import re\n\ndef validate_repo_unset(key: str) -> None:\n    m = re.match(r\"^repos?(?:itories)?(?:\\.(.+?)(?:\\.(url))?)?$\", key)\n    if m and not m.group(1):\n        raise ValueError(\"Cannot unset the entire [repositories] section; specify a repo name\")","typeGuard":"import re\n\ndef has_specific_repo_name(key: str) -> bool:\n    m = re.match(r\"^repos?(?:itories)?(?:\\.(.+?)(?:\\.(url))?)?$\", key)\n    return bool(m and m.group(1))","tryCatchPattern":null,"preventionTips":["Always include the repository name when unsetting: 'repositories.MYNAME --unset'.","Never attempt 'poetry config repositories --unset'.","Unset repositories one at a time if you need to remove all."],"tags":["config-command","valueerror","repositories","protection","cli-validation"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}