astral-sh/ruff · error

Detected project directory

Error message

Detected project directory `{path}` contains non-Unicode characters. ty only supports Unicode paths.

What it means

ty_completion_bench discovers the project root by walking a file's canonicalized ancestors looking for `pyproject.toml`, then converts the found directory to a `SystemPathBuf`. If that ancestor path is not valid UTF-8, it throws this error since ty tooling only supports Unicode paths.

Solutions

  1. Move or rename the project (and its `pyproject.toml` ancestors) so the full path is valid UTF-8
  2. Copy the project into a UTF-8-safe directory (e.g. /tmp/proj) and rerun the benchmark against that copy

Example fix

// before
bench --file /data/caf$(printf '\xe9')/proj/src/mod.py
// after
mv /data/caf$(printf '\xe9')/proj /tmp/proj
bench --file /tmp/proj/src/mod.py
Defensive patterns

Strategy: validation

Validate before calling

import os, sys
file = sys.argv[1]
canonical = os.path.realpath(file)
d = canonical
while d != os.path.dirname(d):
    if os.path.exists(os.path.join(d, 'pyproject.toml')):
        try:
            d.encode('utf-8')
        except UnicodeEncodeError:
            sys.exit(f"Project dir {d!r} is not valid UTF-8")
        break
    d = os.path.dirname(d)

Try / catch

match discover_project_directory(&file) {
    Err(e) if e.to_string().contains("non-Unicode") => eprintln!("Move the project to a UTF-8-safe path and retry"),
    result => result,
}

Prevention

When it happens

Trigger: Running the completion benchmark on a file whose project root (the ancestor containing `pyproject.toml`) has a non-UTF-8 path, e.g. under byte-level filenames on Linux.

Common situations: Projects checked out under directories named with legacy encodings; benchmark harnesses given files in non-Unicode temp or mount paths.

Related errors


AI-assisted analysis of astral-sh/ruff@5bb508f594 (2026-09-05). Data as JSON: /api/errors/e52736cffb825859. Report an issue: GitHub.

Appendix: source

Thrown at crates/ty_completion_bench/src/main.rs:154

    offset: ruff_text_size::TextSize,
) -> anyhow::Result<Vec<Completion<'db>>> {
    let file = system_path_to_file(db, path)
        .with_context(|| format!("failed to get database file for `{path}`"))?;
    let settings = ty_ide::CompletionSettings::default();
    Ok(ty_ide::completion(
        db,
        &settings,
        CompletionCapabilities::default(),
        db.program_file(file),
        offset,
    ))
}

fn discover_project_directory(file: &SystemPath) -> anyhow::Result<SystemPathBuf> {
    for ancestor in file.as_std_path().canonicalize()?.ancestors() {
        if ancestor.join("pyproject.toml").exists() {
            return SystemPathBuf::from_path_buf(ancestor.to_path_buf()).map_err(|path| {
                anyhow!(
                    "Detected project directory `{path}` contains non-Unicode characters. \
                     ty only supports Unicode paths.",
                    path = path.display()
                )
            });
        }
    }
    anyhow::bail!("could not find `pyproject.toml` in any ancestor of `{file}`")
}

View on GitHub (pinned to 5bb508f594)