{"record":{"id":"899ff20f6b911002","repo":"astral-sh/ruff","slug":"could-not-find-pyproject-toml-in-any-ancestor-of","errorCode":null,"errorMessage":"could not find `pyproject.toml` in any ancestor of `{file}`","messagePattern":"could not find `pyproject\\.toml` in any ancestor of `(.+?)`","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ty_completion_bench/src/main.rs","lineNumber":162,"sourceCode":"        CompletionCapabilities::default(),\n        db.program_file(file),\n        offset,\n    ))\n}\n\nfn discover_project_directory(file: &SystemPath) -> anyhow::Result<SystemPathBuf> {\n    for ancestor in file.as_std_path().canonicalize()?.ancestors() {\n        if ancestor.join(\"pyproject.toml\").exists() {\n            return SystemPathBuf::from_path_buf(ancestor.to_path_buf()).map_err(|path| {\n                anyhow!(\n                    \"Detected project directory `{path}` contains non-Unicode characters. \\\n                     ty only supports Unicode paths.\",\n                    path = path.display()\n                )\n            });\n        }\n    }\n    anyhow::bail!(\"could not find `pyproject.toml` in any ancestor of `{file}`\")\n}\n","sourceCodeStart":144,"sourceCodeEnd":164,"githubUrl":"https://github.com/astral-sh/ruff/blob/5bb508f59481c1a02d5c7ff8568b9ffd8a763eef/crates/ty_completion_bench/src/main.rs#L144-L164","documentation":"`discover_project_directory` in `ty_completion_bench` walks up from the supplied file path looking for a `pyproject.toml` that defines the project root. If no ancestor directory contains one, the tool cannot determine the project to benchmark and bails with this message naming the input file.","triggerScenarios":"Invoking `ty_completion_bench <file> <offset>` where `file` lives in a directory tree with no `pyproject.toml` in the file's directory or any parent (e.g. a standalone script in /tmp or a non-Python-project folder).","commonSituations":"Pointing the tool at an isolated .py scratch file outside any project; running on a newly created directory before `uv init`/`cargo`-style project setup; the project uses `setup.py`-only packaging without a `pyproject.toml`; the file path was mistyped so it resolves outside the project.","solutions":["Move the target file inside a directory that has a `pyproject.toml` (or its subtree)","Create a `pyproject.toml` at the project root (`uv init` or a minimal `[project]` table)","Verify the path passed on the command line is correct and inside the intended project","If using a legacy setup.py project, add a minimal `pyproject.toml`"],"exampleFix":"// before\nty_completion_bench /tmp/scratch.py 10   # no pyproject.toml anywhere above /tmp\n// after\nmkdir -p ~/proj && cd ~/proj && uv init && cp /tmp/scratch.py .\nty_completion_bench ~/proj/scratch.py 10","handlingStrategy":"validation","validationCode":"import pathlib\nfile = pathlib.Path(\"path/to/file.py\").resolve()\nassert any((p / \"pyproject.toml\").exists() for p in file.parents), f\"no pyproject.toml above {file}\"","typeGuard":null,"tryCatchPattern":"match tool.run() {\n    Err(e) if e.to_string().starts_with(\"could not find `pyproject.toml`\") => {\n        eprintln!(\"run the tool on a file inside a project with pyproject.toml\");\n        std::process::ExitCode::from(1)\n    }\n    other => other,\n}","preventionTips":["Only pass files that live inside a project with a pyproject.toml at some ancestor level","Double-check the file path argument before running","Add a pyproject.toml to scratch directories where you benchmark regularly"],"tags":["path","project-discovery","pyproject-toml","cli"],"backgroundTag":"project-root-not-found","analyzedSha":"5bb508f59481c1a02d5c7ff8568b9ffd8a763eef","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}