{"record":{"id":"0c9d0843bf32538f","repo":"libnyanpasu/clash-nyanpasu","slug":"path-is-not-valid-utf-8","errorCode":null,"errorMessage":"path is not valid UTF-8: {}","messagePattern":"path is not valid UTF-8: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/core/actor_v2/local_host.rs","lineNumber":66,"sourceCode":"    let kind = match core {\n        ClashCore::ClashPremium => CoreKind::ClashPremium,\n        ClashCore::ClashRs | ClashCore::ClashRsAlpha => CoreKind::ClashRust,\n        ClashCore::Mihomo | ClashCore::MihomoAlpha => CoreKind::Mihomo,\n        ClashCore::Meow => CoreKind::Meow,\n    };\n    let binary_path = find_binary(&core_type)?;\n\n    Ok(CoreSpec {\n        kind,\n        binary_path: to_utf8(binary_path)?,\n        version: None,\n        features: vec![],\n    })\n}\n\nfn to_utf8(path: std::path::PathBuf) -> Result<Utf8PathBuf> {\n    Utf8PathBuf::from_path_buf(path)\n        .map_err(|path| anyhow::anyhow!(\"path is not valid UTF-8: {}\", path.to_string_lossy()))\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[tokio::test]\n    async fn the_local_host_spawns_under_a_temp_root() {\n        let root = tempfile::TempDir::new().unwrap();\n        let paths =\n            PathResolver::with_base_dirs(root.path().join(\"config\"), root.path().join(\"data\"));\n\n        let control = build(&paths).await.unwrap();\n\n        let _ = control.status();\n        assert!(!control.executor_is_closed());\n    }\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/core/actor_v2/local_host.rs#L48-L84","documentation":"The `to_utf8` helper in `core/actor_v2/local_host.rs` converts a `std::path::PathBuf` into a `Utf8PathBuf` and fails with this error when the path contains bytes that are not valid UTF-8 (possible on Unix where paths are arbitrary bytes). The actor-local host layer requires UTF-8 paths so they can be used in typed/string-based APIs, so non-UTF-8 paths are rejected eagerly with the lossy-decoded path in the message.","triggerScenarios":"Building or passing a filesystem path to the local-host actor helpers where a directory or filename was created with non-UTF-8 bytes (e.g. locale-mismatched bytes on Linux, files created by tools using non-UTF-8 encodings); any code path calling `to_utf8` with such a PathBuf.","commonSituations":"App installed under a path with non-UTF-8 bytes; user profiles/config dirs on a system with a legacy locale (LC_ALL=C, ISO-8859-1 filenames); extracted archives with mangled filenames; network mounts exposing raw-byte names.","solutions":["Rename the offending file/directory so its path is valid UTF-8 (the error message shows the lossy name to find it).","Set the system locale to a UTF-8 locale (e.g. LANG=en_US.UTF-8) so paths decode correctly.","Check the configured app/profile data directory (env vars like HOME/XDG dirs) for non-UTF-8 bytes and fix it.","If you control the caller, validate paths early with `to_str()` and surface a clear configuration error."],"exampleFix":"// before\nlet host = LocalHost::build(to_utf8(path)?);\n// after\nlet path = to_utf8(path).map_err(|e| {\n    log::error!(\"app path must be UTF-8: {e}; move the app or fix the locale\");\n    e\n})?;\nlet host = LocalHost::build(path);","handlingStrategy":"validation","validationCode":"if path.to_str().is_none() {\n    anyhow::bail!(\"path {:?} is not valid UTF-8; move the app or fix the system locale\", path);\n}","typeGuard":"fn is_utf8_path(path: &std::path::Path) -> bool {\n    path.to_str().is_some()\n}","tryCatchPattern":"let utf8_path = to_utf8(path)\n    .with_context(|| format!(\"configure a UTF-8 app path (got {:?})\", path))\n    .map_err(|e| { log::error!(\"{e:#}\"); e })?;","preventionTips":["Install the app under an ASCII/UTF-8 path","Use a UTF-8 system locale (LANG/LC_ALL=en_US.UTF-8) on Linux","Validate configured data/profile directories for non-UTF-8 bytes at startup","Avoid deriving app paths from user-controlled non-UTF-8 filenames"],"tags":["rust","filesystem","encoding","utf-8","path"],"backgroundTag":"invalid-argument-format","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}