{"id":"3c4e495bf4028b59","repo":"python-poetry/poetry","slug":"repository-repository-name-is-not-defined","errorCode":null,"errorMessage":"Repository {repository_name} is not defined","messagePattern":"Repository (.+?) is not defined","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/poetry/publishing/publisher.py","lineNumber":60,"sourceCode":"\n    def publish(\n        self,\n        repository_name: str | None,\n        username: str | None,\n        password: str | None,\n        cert: Path | None = None,\n        client_cert: Path | None = None,\n        dry_run: bool = False,\n        skip_existing: bool = False,\n    ) -> None:\n        if not repository_name:\n            url = \"https://upload.pypi.org/legacy/\"\n            repository_name = \"pypi\"\n        else:\n            # Retrieving config information\n            url = self._poetry.config.get([\"repositories\", repository_name, \"url\"])\n            if url is None:\n                raise RuntimeError(f\"Repository {repository_name} is not defined\")\n            url = _normalize_legacy_repository_url(url)\n\n        if not (username and password):\n            # Check if we have a token first\n            token = self._authenticator.get_pypi_token(repository_name)\n            if token:\n                logger.debug(\"Found an API token for %s.\", repository_name)\n                username = \"__token__\"\n                password = token\n            else:\n                auth = self._authenticator.get_http_auth(repository_name)\n                if auth:\n                    logger.debug(\n                        \"Found authentication information for %s.\", repository_name\n                    )\n                    username = auth.username\n                    password = auth.password\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/publishing/publisher.py#L42-L78","documentation":"Raised by Publisher.publish() when a repository_name is supplied but Poetry's config has no repositories.<name>.url entry. Poetry needs an explicit URL to know where to upload; an undefined name is treated as a configuration error rather than guessing.","triggerScenarios":"Running `poetry publish -r myrepo` (or passing repository_name='myrepo') when `poetry config repositories.myrepo.url` was never set. The lookup `config.get(['repositories', repository_name, 'url'])` returns None.","commonSituations":"Forgot to configure the repository before publishing; typo in the repository name on the CLI vs. config; config stored in a different scope (local vs global) than the one being read; new team member who hasn't run the config commands.","solutions":["Register the repository: `poetry config repositories.<name> <url>`.","Double-check the name passed to `--repository`/`-r` matches the configured key exactly (case-sensitive).","If the URL is in a different config scope, set it explicitly (`--local` for project-level, default for global).","For one-off use, fall back to the default PyPI by omitting `-r`."],"exampleFix":"// before\n$ poetry publish -r internal\nRuntimeError: Repository internal is not defined\n\n// after\n$ poetry config repositories.internal https://internal.pypi/simple/\n$ poetry publish -r internal","handlingStrategy":"validation","validationCode":"def repository_is_configured(config, name: str) -> bool:\n    return config.get([\"repositories\", name, \"url\"]) is not None","typeGuard":null,"tryCatchPattern":"from poetry.publishing.publisher import Publisher\n\ntry:\n    publisher.publish(repository_name=name, username=u, password=p)\nexcept RuntimeError as e:\n    if \"is not defined\" in str(e):\n        # register the repository then retry\n        ...","preventionTips":["Configure repositories with `poetry config repositories.<name> <url>` before publishing.","Document required `poetry config` commands in the project setup guide.","Use a pre-publish script that asserts the repository is configured.","Double-check the repository name spelling on the CLI."],"tags":["publishing","config","repository"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}