{"record":{"id":"2db143589d751e07","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-app-path","errorCode":null,"errorMessage":"failed to get app_path","messagePattern":"failed to get app_path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/core/sysopt.rs","lineNumber":227,"sourceCode":"    pub fn init_launch(&self) -> Result<()> {\n        let enable = { Config::verge().latest().enable_auto_launch };\n        let enable = enable.unwrap_or(false);\n\n        log::info!(target: \"app\", \"Initializing auto-launch with enable={}\", enable);\n\n        let app_exe = current_exe()?;\n        let app_exe = dunce::canonicalize(app_exe)?;\n        log::debug!(target: \"app\", \"Resolved app executable path: {:?}\", app_exe);\n\n        let app_name = app_exe\n            .file_stem()\n            .and_then(|f| f.to_str())\n            .ok_or(anyhow!(\"failed to get file stem\"))?;\n\n        let app_path = app_exe\n            .as_os_str()\n            .to_str()\n            .ok_or(anyhow!(\"failed to get app_path\"))?\n            .to_string();\n\n        log::debug!(target: \"app\", \"Initial app path: {}\", app_path);\n\n        // fix issue #26\n        #[cfg(target_os = \"windows\")]\n        let app_path = format!(\"\\\"{app_path}\\\"\");\n        #[cfg(target_os = \"windows\")]\n        log::debug!(target: \"app\", \"Windows formatted app path: {}\", app_path);\n\n        // use the /Applications/Clash Nyanpasu.app path\n        #[cfg(target_os = \"macos\")]\n        let app_path = (|| -> Option<String> {\n            let path = std::path::PathBuf::from(&app_path);\n            let path = path.parent()?.parent()?.parent()?;\n            let extension = path.extension()?.to_str()?;\n            match extension == \"app\" {\n                true => Some(path.as_os_str().to_str()?.to_string()),","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/core/sysopt.rs#L209-L245","documentation":"init_launch converts the canonicalized executable path's OsStr to a Rust String for the auto-launch registration. If the path contains bytes that are not valid UTF-16/UTF-8 convertible (on Windows paths are WTF-16; non-Unicode sequences fail to_str), the error is thrown. It blocks configuring system auto-start.","triggerScenarios":"update_launch -> init_launch when the app executable path contains characters unrepresentable as UTF-8 (rare malformed Windows path components), so app_exe.as_os_str().to_str() returns None.","commonSituations":"Executables placed in folders with corrupted or mixed-encoding names, unusual unattended installs, or portable builds run from mapped drives with odd names.","solutions":["Relocate the application to a path using standard Unicode characters","Use to_string_lossy() if approximate paths are acceptable for auto-launch","Skip auto-launch registration with a clear log instead of failing hard"],"exampleFix":"// before\nlet app_path = app_exe.as_os_str().to_str().ok_or(anyhow!(\"failed to get app_path\"))?.to_string();\n// after\nlet app_path = app_exe.to_string_lossy().into_owned();","handlingStrategy":"validation","validationCode":"let exe = std::env::current_exe()?;\nif exe.to_str().is_none() {\n    eprintln!(\"executable path {:?} is not valid UTF-8; auto-launch registration may fail\", exe);\n}","typeGuard":"fn path_is_utf8(p: &std::path::Path) -> bool {\n    p.as_os_str().to_str().is_some()\n}","tryCatchPattern":"match init_launch(app_exe) {\n    Ok(launch) => launch,\n    Err(e) if e.to_string().contains(\"app_path\") => /* fall back to to_string_lossy or skip auto-launch with warning */,\n    Err(e) => return Err(e),\n}","preventionTips":["Keep install paths free of non-Unicode/malformed characters","Prefer PathBuf/OsString end-to-end instead of forcing paths into String early","Use to_string_lossy() when the consumer only needs an approximate path"],"tags":["rust","filesystem","path","encoding","autostart"],"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"}