{"record":{"id":"5d0e173b4cf81bf9","repo":"libnyanpasu/clash-nyanpasu","slug":"application-failed-to-start","errorCode":null,"errorMessage":"application failed to start","messagePattern":"application failed to start","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"backend/tauri/src/utils/help.rs","lineNumber":290,"sourceCode":"    app_handle.exit(0);\n}\n\n#[instrument(skip(app_handle))]\npub fn restart_application(app_handle: &AppHandle) {\n    cleanup_processes(app_handle);\n    let env = app_handle.env();\n    let path = current_binary(&env).unwrap();\n    let arg = std::env::args().collect::<Vec<String>>();\n    let mut args = vec![\"launch\".to_string(), \"--\".to_string()];\n    // filter out the first arg\n    if arg.len() > 1 {\n        args.extend(arg.iter().skip(1).cloned());\n    }\n    tracing::info!(\"restart app: {:#?} with args: {:#?}\", path, args);\n    std::process::Command::new(path)\n        .args(args)\n        .spawn()\n        .expect(\"application failed to start\");\n    app_handle.exit(0);\n    std::process::exit(0);\n}\n\n#[macro_export]\nmacro_rules! error {\n    ($result: expr) => {\n        log::error!(target: \"app\", \"{:?}\", $result);\n    };\n}\n\n#[macro_export]\nmacro_rules! log_err {\n    ($result: expr) => {\n        if let Err(err) = $result {\n            log::error!(target: \"app\", \"{:#?}\", err);\n        }\n    };","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/help.rs#L272-L308","documentation":"`restart_application` respawns the current executable with the original args and then exits. The `expect` panics if `Command::spawn()` fails, i.e. the OS refused to launch the new process. Because the function was about to exit the app anyway, a failed spawn leaves the user with an app that dies without restarting.","triggerScenarios":"Calling `restart_application` (e.g. after an update install or a 'restart to apply' action) when the resolved `path` no longer exists (binary replaced/moved during an update), lacks execute permission, or spawn fails due to OS limits/AV interference.","commonSituations":"Auto-updater swapped the executable file before restart; app installed in a directory whose binary name changed; portable executables on a drive that was unmounted; Windows file lock still held on the old binary.","solutions":["Verify `path` exists and is executable before spawning (e.g. `path.exists()` plus a graceful error path).","On updates, wait for the old file to be fully written/renamed and file locks released before restarting.","Replace the `.expect` with a fallback: log the error and keep the current process alive instead of exiting.","Check OS-specific causes (exec permissions, AV/quarantine, missing exec directory) if it reproduces on user machines."],"exampleFix":"// before\nstd::process::Command::new(path)\n    .args(args)\n    .spawn()\n    .expect(\"application failed to start\");\napp_handle.exit(0);\n// after\nif let Err(e) = std::process::Command::new(path).args(args).spawn() {\n    tracing::error!(\"failed to restart application: {e}\");\n    return; // keep the current instance alive\n}\napp_handle.exit(0);","handlingStrategy":"try-catch","validationCode":"if !path.exists() {\n    tracing::error!(\"cannot restart: executable missing at {}\", path.display());\n    return;\n}","typeGuard":null,"tryCatchPattern":"match std::process::Command::new(path).args(args).spawn() {\n    Ok(child) => { /* proceed with exit */ }\n    Err(e) => {\n        tracing::error!(\"restart spawn failed: {e}; staying alive\");\n        return;\n    }\n}","preventionTips":["Never swap/delete the executable while it may be re-spawned; use atomic rename after full write","Test restart after auto-update on each target platform","Keep the current process alive when spawn fails instead of unconditionally exiting"],"tags":["rust","process-spawn","restart","panic"],"backgroundTag":"command-not-found","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"}