{"record":{"id":"674af99a410444d9","repo":"libnyanpasu/clash-nyanpasu","slug":"non-utf-8-destination","errorCode":null,"errorMessage":"non-UTF-8 destination","messagePattern":"non-UTF-8 destination","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/client/core_lifecycle/adapters.rs","lineNumber":34,"sourceCode":"#[async_trait]\nimpl BinaryInstaller for FsBinaryInstaller {\n    async fn install(&self, artifact: &PreparedCoreBinary) -> anyhow::Result<()> {\n        if let Err(error) = tokio::fs::copy(&artifact.source, &artifact.destination).await {\n            tracing::warn!(%error, \"core copy failed; requesting elevated installation\");\n            let source = artifact.source.clone();\n            let destination = artifact.destination.clone();\n            // The blocking task itself retains the staging files if its waiter dies.\n            let staging = artifact.staging.clone();\n            let status = tokio::task::spawn_blocking(move || {\n                let _staging = staging;\n                #[cfg(target_os = \"windows\")]\n                {\n                    let source = source\n                        .to_str()\n                        .ok_or_else(|| anyhow::anyhow!(\"non-UTF-8 source\"))?;\n                    let destination = destination\n                        .to_str()\n                        .ok_or_else(|| anyhow::anyhow!(\"non-UTF-8 destination\"))?;\n                    Ok::<_, anyhow::Error>(\n                        runas::Command::new(\"cmd\")\n                            .args(&[\n                                \"/C\",\n                                \"copy\",\n                                \"/Y\",\n                                source,\n                                destination.trim_start_matches(r\"\\\\?\\\"),\n                            ])\n                            .status()?,\n                    )\n                }\n                #[cfg(not(target_os = \"windows\"))]\n                {\n                    Ok::<_, anyhow::Error>(\n                        runas::Command::new(\"cp\")\n                            .arg(\"-f\")\n                            .arg(source)","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/client/core_lifecycle/adapters.rs#L16-L52","documentation":"Same mechanism as the \"non-UTF-8 source\" error, but for the destination path of the elevated Windows copy: destination.to_str() returns None because the target path's OsStr is not valid UTF-8. The elevated cmd.exe /C copy invocation requires a &str, so installation aborts.","triggerScenarios":"Calling FsBinaryInstaller::install on Windows where artifact.destination (the install target, e.g. the install dir core path) contains non-UTF-8 bytes and the initial tokio::fs::copy failed, forcing the runas path.","commonSituations":"Application installed under a directory whose name comes from a non-UTF-8-encodable locale string, UNC paths with non-UTF-8 components, or a user-chosen install directory with legacy-codepage characters.","solutions":["Install the app (or set the core destination) under a path with only UTF-8-representable characters and reinstall/redo the core install.","Strip the \\\\?\\ verbatim prefix and normalize the destination path before conversion, or use short path names for the cmd invocation.","Use to_string_lossy with a logged warning when exact fidelity is acceptable, instead of hard-failing.","Route the elevated copy through a mechanism taking OsStr/PathBuf (e.g. PowerShell with explicit encoding) rather than cmd.exe string args."],"exampleFix":"// before\nlet destination = destination.to_str().ok_or_else(|| anyhow::anyhow!(\"non-UTF-8 destination\"))?;\n// after\nlet destination = destination.to_str().map(str::to_owned).unwrap_or_else(|| {\n    tracing::warn!(\"destination not UTF-8; using lossy path\");\n    destination.to_string_lossy().into_owned()\n});","handlingStrategy":"validation","validationCode":"fn ensure_utf8_path(p: &std::path::Path) -> anyhow::Result<()> {\n    anyhow::ensure!(p.to_str().is_some(), \"destination is not valid UTF-8: {:?}\", p);\n    Ok(())\n}","typeGuard":"fn valid_utf8_path(p: &std::path::Path) -> Option<&str> { p.to_str() }","tryCatchPattern":"if let Err(e) = installer.install(&artifact).await {\n    if e.to_string().contains(\"non-UTF-8 destination\") {\n        tracing::warn!(\"install dir not UTF-8; falling back to short-path install\");\n        install_with_short_paths(&artifact).await?;\n    } else { return Err(e); }\n}","preventionTips":["Install the application into UTF-8-safe directories","Normalize/strip \\\\?\\ verbatim prefixes before invoking shell copies","Log path lossiness early at startup so encoding issues surface before install time"],"tags":["windows","path","encoding","filesystem"],"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"}