{"id":"bf68dadd6ec1573c","repo":"python-poetry/poetry","slug":"destination-fg-yellow-path-exists-and-is-not","errorCode":null,"errorMessage":"Destination <fg=yellow>{path}</> exists and is not empty. Did you mean `poetry init`?","messagePattern":"Destination <fg=yellow>(.+?)</> exists and is not empty\\. Did you mean `poetry init`\\?","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/poetry/console/commands/new.py","lineNumber":77,"sourceCode":"\n    def handle(self) -> int:\n        from pathlib import Path\n\n        if self.io.input.option(\"project\"):\n            self.line_error(\n                \"<warning>--project only makes sense with existing projects, and will\"\n                \" be ignored. You should consider the option --path instead.</warning>\"\n            )\n\n        path = Path(self.argument(\"path\"))\n        if not path.is_absolute():\n            # we do not use resolve here due to compatibility issues\n            # for path.resolve(strict=False)\n            path = Path.cwd().joinpath(path)\n\n        if path.exists() and list(path.glob(\"*\")):\n            # Directory is not empty. Aborting.\n            raise RuntimeError(\n                f\"Destination <fg=yellow>{path}</> exists and is not empty. Did you mean `poetry init`?\"\n            )\n\n        if self.option(\"src\"):\n            self.line_error(\n                \"The <c1>--src</> option is now the default and will be removed in a future version.\"\n            )\n\n        return self._init_pyproject(\n            project_path=path,\n            allow_interactive=self.option(\"interactive\"),\n            layout_name=\"standard\" if self.option(\"flat\") else \"src\",\n            readme_format=self.option(\"readme\") or \"md\",\n            allow_layout_creation_on_empty=True,\n        )\n","sourceCodeStart":59,"sourceCodeEnd":93,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/console/commands/new.py#L59-L93","documentation":"RuntimeError from `poetry new` (new.py:75-79) when the destination path both exists and contains at least one entry (`list(path.glob('*'))` is non-empty). `new` scaffolds a fresh project; for existing directories use `poetry init`.","triggerScenarios":"Running `poetry new mypkg` where `mypkg/` already exists with files; running inside a repo directory that is non-empty.","commonSituations":"Re-scaffolding over an existing project; choosing a name that collides with a sibling directory; misunderstanding `new` vs `init`.","solutions":["Use `poetry init` in the existing directory to adopt it.","Pick a fresh path: `poetry new mypkg-v2`.","Empty or remove the existing directory if you truly want a clean scaffold."],"exampleFix":"# before\npoetry new existing-dir\n# after\ncd existing-dir && poetry init","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(\"mypkg\")\nif p.exists() and any(p.iterdir()):\n    raise SystemExit(f\"{p} is non-empty; use `poetry init` instead\")","typeGuard":"def is_empty_or_missing(path: str) -> bool:\n    from pathlib import Path\n    p = Path(path)\n    return not p.exists() or not any(p.iterdir())","tryCatchPattern":null,"preventionTips":["Prefer `poetry init` for existing directories.","Check the target path before scripting `poetry new`.","Keep scaffolding tooling idempotent by choosing unique names."],"tags":["new","scaffolding","filesystem"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}