{"record":{"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":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/workspace.rs","lineNumber":2096,"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":2078,"sourceCodeEnd":2114,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/workspace/workspace.rs#L2078-L2114","documentation":"In the same `resolve_relative_path` function, when `diff_paths` succeeds the resulting `PathBuf` is converted to a string via `to_str()`. If the path contains non-UTF-8 bytes (valid on Unix for arbitrary OS paths), `to_str()` returns `None` and the function errors, interpolating the label and the lossy display of the path. This guards downstream string handling from non-UTF-8 paths.","triggerScenarios":"Calling `resolve_relative_path` where the relativized result contains invalid UTF-8 bytes — typically on Unix when a workspace path component uses non-UTF-8 bytes (e.g. a directory named with Latin-1 or raw bytes), and `diff_paths` produces a relative path preserving those bytes.","commonSituations":"Workspaces created by tooling that preserves byte-accurate names, files copied from systems with different encodings, or deliberately non-UTF-8 paths used in test fixtures. The error surfaces the moment Cargo tries to treat the path as a string for lockfile/manifest relativization.","solutions":["Rename the offending path component(s) to valid UTF-8 so `to_str()` succeeds.","Set the `LANG`/`LC_ALL` locale appropriately and ensure the filesystem path is UTF-8 encoded.","Move the workspace to a directory tree whose every component is valid UTF-8."],"exampleFix":"# before: a non-UTF-8 directory name (e.g. raw bytes)\nmv $'bad\\xffdir' gooddir\n# then re-run cargo — resolve_relative_path will succeed","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn all_components_utf8(p: &Path) -> bool {\n    p.components().all(|c| c.as_os_str().is_char_boundary(0) && c.as_os_str().to_str().is_some())\n}\n// verify every workspace path component is UTF-8 before path relativization\nassert!(all_components_utf8(Path::new(\"/Users/me/ws\")));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict workspace paths to valid UTF-8 components.","Avoid copying directories with legacy/Latin-1 names into workspace trees.","Run a pre-build lint that fails on non-UTF-8 path components."],"tags":["path","utf8","encoding","unix","cargo"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}