astral-sh/ruff · error
path `{}` is not valid UTF-8
Error message
path `{}` is not valid UTF-8 What it means
While copying a fixture's files into the eval temp directory, the walk converts every visited entry to a `SystemPath`; any file or directory inside the fixture whose name is not valid UTF-8 aborts with this message and the path echoed. Dot-prefixed entries are filtered out before this, so hidden dirs like `.venv` are not the cause.
Source
Thrown at crates/ty_completion_eval/src/main.rs:561
fn copy_project(src_dir: &SystemPath, dst_dir: &SystemPath) -> anyhow::Result<Vec<Cursor>> {
std::fs::create_dir_all(dst_dir).with_context(|| dst_dir.to_string())?;
let mut cursors = vec![];
let it = walkdir::WalkDir::new(src_dir.as_std_path())
.sort_by_file_name()
.into_iter()
.filter_entry(|dent| {
!dent
.file_name()
.to_str()
.is_some_and(|name| name.starts_with('.'))
});
for result in it {
let dent =
result.with_context(|| format!("failed to get directory entry from {src_dir}"))?;
let src = SystemPath::from_std_path(dent.path()).ok_or_else(|| {
anyhow::anyhow!("path `{}` is not valid UTF-8", dent.path().display())
})?;
let name = src
.strip_prefix(src_dir)
.expect("descendent of `src_dir` must start with `src`");
// let name = src
// .file_name()
// .ok_or_else(|| anyhow::anyhow!("path `{src}` is missing a basename"))?;
let dst = dst_dir.join(name);
if dent.file_type().is_dir() {
std::fs::create_dir_all(dst.as_std_path())
.with_context(|| format!("failed to create directory `{dst}`"))?;
} else {
cursors.extend(copy_file(src, &dst)?);
}
}
anyhow::ensure!(
!cursors.is_empty(),
"could not find any `<CURSOR>` directives in any of the files in `{src_dir}`",View on GitHub (pinned to 672bb4edf0)
Solutions
- Detect offenders: `find <fixture-dir> -print0 | while IFS= read -r -d '' f; do printf '%s' "$f" | iconv -f utf-8 -t utf-8 >/dev/null 2>&1 || echo "non-UTF-8: $f"; done`
- Delete or rename the reported paths, and keep fixtures to committed files only (`git status` / `git clean` on the fixture)
- Review what created the file and disable it for the truth tree (e.g. run builds outside the fixtures)
Example fix
# before: run aborts with `path ... is not valid UTF-8` # after: clean the fixture, then re-run git clean -fdx crates/ty_completion_eval/truth/<fixture> cargo run -p ty_completion_eval -- all
Defensive patterns
Strategy: validation
Validate before calling
find crates/ty_completion_eval/truth -print0 \
| while IFS= read -r -d '' f; do
printf '%s' "$f" | iconv -f utf-8 -t utf-8 >/dev/null 2>&1 \
|| echo "non-UTF-8 path: $f" >&2
done Prevention
- Keep fixtures to committed files only; run builds outside the truth tree
- `git clean -fdx` fixtures before eval runs
- Never sync or build inside truth fixtures
When it happens
Trigger: A non-UTF-8-named file or directory inside a truth fixture project — build droppings, cache files, or extraction residue — encountered during the recursive copy from `truth/` into the temp eval dir.
Common situations: Fixtures that once held real project artifacts (`.tox`, caches with byte names); files synced from Windows with mangled encodings; fuzzing residue committed accidentally.
Related errors
- truth source directory `{path}` contains invalid UTF-8
- The current working directory `{}` contains non-Unicode char
- The current working directory `{}` contains non-Unicode char
- Detected project directory `{path}` contains non-Unicode cha
- {truth} does not exist: ty's completion evaluation must be r
AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16).
Data as JSON: /api/errors/02b142eef365a479.
Report an issue: GitHub.