{"id":"07df17af2ee9358f","repo":"rust-lang/cargo","slug":"resolved-to-non-utf-value","errorCode":null,"errorMessage":"`{}` resolved to non-UTF value (`{}`)","messagePattern":"`(.+?)` resolved to non-UTF value \\(`(.+?)`\\)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/workspace.rs","lineNumber":2151,"sourceCode":"\npub fn resolve_relative_path(\n    label: &str,\n    old_root: &Path,\n    new_root: &Path,\n    rel_path: &str,\n) -> CargoResult<String> {\n    let joined_path = normalize_path(&old_root.join(rel_path));\n    match diff_paths(joined_path, new_root) {\n        None => Err(anyhow!(\n            \"`{}` was defined in {} but could not be resolved with {}\",\n            label,\n            old_root.display(),\n            new_root.display()\n        )),\n        Some(path) => Ok(path\n            .to_str()\n            .ok_or_else(|| {\n                anyhow!(\n                    \"`{}` resolved to non-UTF value (`{}`)\",\n                    label,\n                    path.display()\n                )\n            })?\n            .to_owned()),\n    }\n}\n\n/// Finds the path of the root of the workspace.\npub fn find_workspace_root(\n    manifest_path: &Path,\n    gctx: &GlobalContext,\n) -> CargoResult<Option<PathBuf>> {\n    find_workspace_root_with_loader(manifest_path, gctx, |self_path| {\n        let source_id = SourceId::for_manifest_path(self_path)?;\n        let manifest = read_manifest(self_path, source_id, gctx)?;\n        Ok(manifest","sourceCodeStart":2133,"sourceCodeEnd":2169,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/workspace.rs#L2133-L2169","documentation":"Returned by `resolve_relative_path` (src/workspace/workspace.rs:2151) when `diff_paths` succeeded but `to_str()` returned `None` — the resolved relative path contains bytes that are not valid UTF-8. On Unix filenames are arbitrary bytes, so a non-UTF8 directory/file name in the path makes it impossible to embed into a TOML manifest or Cargo.toml, and the function errors with the label and the lossy display of the path.","triggerScenarios":"Any path component under `old_root`/`new_root`/`rel_path` containing non-UTF8 bytes (common on Linux where filenames are byte strings), surfaced when `path.to_str()` is `None`.","commonSituations":"Files created by tooling that uses Latin-1 or raw byte names; mounts with odd encodings; copying a workspace from a system with a different locale; `tar` extraction preserving non-UTF8 entry names.","solutions":["Rename the offending file/directory so every component is valid UTF-8 (`convmv -r -f latin1 -t utf8 .` on Linux).","Move the workspace to a path composed entirely of UTF-8 characters.","Avoid non-ASCII or raw-byte names in directories Cargo must traverse."],"exampleFix":"# rename a non-UTF8 directory\nconvvm -r --notest -f latin1 -t utf8 ./bad-name\n# then re-run cargo","handlingStrategy":"validation","validationCode":"fn all_utf8(p: &std::path::Path) -> bool { p.to_str().is_some() }\n// assert all_utf8(&old_root) && all_utf8(&new_root) && all_utf8(&joined)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all workspace paths valid UTF-8.","Run `convmv` on imported trees with non-UTF8 names.","Avoid extracting archives that preserve non-UTF8 entry names."],"tags":["cargo","path","utf8","filesystem","encoding"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}