{"record":{"id":"1fbab6442a069b25","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-file-stem","errorCode":null,"errorMessage":"failed to get file stem","messagePattern":"failed to get file stem","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/core/sysopt.rs","lineNumber":222,"sourceCode":"\n        Ok(())\n    }\n\n    /// init the auto launch\n    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> {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/core/sysopt.rs#L204-L240","documentation":"init_launch resolves the current executable path (dunce::canonicalize) and extracts its file_stem to register auto-launch. If the canonicalized path has no file stem or the stem is not valid UTF-8, the error is thrown. On normal installs this is impossible; it indicates a corrupted or exotic executable path.","triggerScenarios":"Calling update_launch -> init_launch when current_exe() yields a path whose file_name is missing (e.g. \"/\" or a drive root) or whose stem contains invalid UTF-8 (non-Unicode path components).","commonSituations":"App installed in a directory with non-UTF-8 (e.g. GBK-encoded) characters on Windows, running from a temp/deleted path, or unusual portable deployments where the exe path degenerates.","solutions":["Move/install the app to a plain ASCII path without special characters","Log the canonicalized app_exe path to diagnose the malformed path","Fall back to the full file_name() string when file_stem() is unavailable"],"exampleFix":"// before\nlet app_name = app_exe.file_stem().and_then(|f| f.to_str()).ok_or(anyhow!(\"failed to get file stem\"))?;\n// after\nlet app_name = app_exe.file_stem().or_else(|| app_exe.file_name()).and_then(|f| f.to_str()).ok_or_else(|| anyhow!(\"failed to get file stem from {:?}\", app_exe))?;","handlingStrategy":"validation","validationCode":"let exe = std::env::current_exe()?;\nif exe.file_stem().and_then(|s| s.to_str()).is_none() {\n    eprintln!(\"executable path {:?} has no valid UTF-8 file stem; auto-launch will fail\", exe);\n}","typeGuard":"fn has_valid_stem(p: &std::path::Path) -> bool {\n    p.file_stem().and_then(|s| s.to_str()).is_some()\n}","tryCatchPattern":"match init_launch(app_exe) {\n    Ok(launch) => launch,\n    Err(e) if e.to_string().contains(\"file stem\") => /* log path, degrade: skip auto-launch setup */,\n    Err(e) => return Err(e),\n}","preventionTips":["Install the app under an ASCII-safe directory","Log the canonicalized exe path during startup to catch path anomalies early","Degrade gracefully: skipping auto-launch registration is better than failing startup"],"tags":["rust","filesystem","path","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"}