{"record":{"id":"51329a553ef61955","repo":"PrefectHQ/fastmcp","slug":"failed-to-initialize-project-e-stderr","errorCode":null,"errorMessage":"Failed to initialize project: {e.stderr}","messagePattern":"Failed to initialize project: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/utilities/mcp_server_config/v1/environments/uv.py","lineNumber":163,"sourceCode":"                    \"init\",\n                    \"--project\",\n                    str(output_dir),\n                    \"--name\",\n                    \"fastmcp-env\",\n                ],\n                check=True,\n                capture_output=True,\n                text=True,\n            )\n        except subprocess.CalledProcessError as e:\n            # If project already exists, that's fine - continue\n            if \"already initialized\" in e.stderr.lower():\n                logger.debug(\n                    f\"Project already initialized at {output_dir}, continuing...\"\n                )\n            else:\n                logger.error(f\"Failed to initialize project: {e.stderr}\")\n                raise RuntimeError(f\"Failed to initialize project: {e.stderr}\") from e\n\n        # Pin Python version if specified\n        if self.python:\n            logger.debug(f\"Pinning Python version to {self.python}\")\n            try:\n                subprocess.run(\n                    [\n                        \"uv\",\n                        \"python\",\n                        \"pin\",\n                        self.python,\n                        \"--project\",\n                        str(output_dir),\n                    ],\n                    check=True,\n                    capture_output=True,\n                    text=True,\n                )","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/utilities/mcp_server_config/v1/environments/uv.py#L145-L181","documentation":"During `prepare()`, the environment runs `uv init` (via subprocess) to create the persistent project directory. If that command fails, the code checks whether stderr contains 'already initialized' (benign) and otherwise logs and re-raises RuntimeError with the captured stderr so the underlying uv failure is visible.","triggerScenarios":"`uv init` exiting non-zero for reasons other than 'already initialized' — e.g. output_dir not writable, output_dir contains conflicting files, malformed pyproject.toml in the target, disk full, or an incompatible/old uv version.","commonSituations":"Pointing output_dir at a directory that already has a broken/partial project; read-only or permission-restricted directories; corporate proxies blocking uv's network access during init; stale uv version whose error text differs so the benign case isn't matched.","solutions":["Read the stderr in the exception message and fix the underlying `uv init` failure (permissions, existing conflicting pyproject.toml, etc.).","Ensure output_dir is writable and does not contain a conflicting/invalid project — or clean it out.","Upgrade uv to the latest version (`uv self update` or reinstall) so error text and behavior match.","Run `uv init <output_dir>` manually to reproduce and see the full error."],"exampleFix":"// before (CI)\n- run: fastmcp run server.py\n// after\n- run: rm -rf .fastmcp-env && uv self update\n- run: fastmcp run server.py","handlingStrategy":"try-catch","validationCode":"import subprocess\ndef preflight_uv_init(output_dir):\n    r = subprocess.run(['uv', 'init', str(output_dir)], capture_output=True, text=True)\n    if r.returncode != 0 and 'already initialized' not in r.stderr.lower():\n        raise RuntimeError(f'uv init would fail: {r.stderr}')","typeGuard":null,"tryCatchPattern":"try:\n    env.prepare(output_dir=dir)\nexcept RuntimeError as e:\n    if 'Failed to initialize project' in str(e):\n        shutil.rmtree(dir, ignore_errors=True)\n        env.prepare(output_dir=dir)\n    else:\n        raise","preventionTips":["Ensure output_dir is empty or a valid existing uv project","Keep uv updated to the latest version","Verify directory write permissions and disk space before prepare()"],"tags":["environment","uv","subprocess","project-init"],"backgroundTag":"subprocess-command-failed","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}