{"record":{"id":"59439131d46075c5","repo":"libnyanpasu/clash-nyanpasu","slug":"exit-code-signal-output","errorCode":null,"errorMessage":"exit code: {:?}, signal: {:?}, output: {}","messagePattern":"exit code: (.+?), signal: (.+?), output: (.+?)","errorType":"exception","errorClass":"std::io::Error (Other)","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/sudo.rs","lineNumber":48,"sourceCode":"                .as_ref(),\n        );\n        tracing::debug!(\"prepare script: {}\", script_content);\n        std::fs::write(&script, script_content)?;\n        let status = std::process::Command::new(\"osascript\")\n            .arg(\"-e\")\n            .args([&format!(\n                r#\"do shell script \"bash {} &> {}\" with administrator privileges\"#,\n                script.to_string_lossy(),\n                out.to_string_lossy()\n            )])\n            .status();\n        match status {\n            Ok(status) if status.success() => Ok(()),\n            Ok(status) => {\n                // read the output file\n                let output = std::fs::read_to_string(out)\n                    .unwrap_or_else(|e| format!(\"failed to read output file: {}\", e));\n                Err(std::io::Error::new(\n                    std::io::ErrorKind::Other,\n                    format!(\n                        \"exit code: {:?}, signal: {:?}, output: {}\",\n                        status.code(),\n                        status.signal(),\n                        output\n                    ),\n                ))\n            }\n            Err(e) => Err(std::io::Error::new(\n                std::io::ErrorKind::Other,\n                e.to_string(),\n            )),\n        }\n    }\n}\n\n#[cfg(target_os = \"macos\")]","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/sudo.rs#L30-L66","documentation":"The `sudo` helper runs a privileged command via a sudo wrapper (e.g. sudo-prompt/OS auth) and, when the spawned process exits non-zero (or is killed by a signal), reads its captured output file and returns this formatted error containing exit code, signal, and stdout/stderr content.","triggerScenarios":"Calling `sudo` with a command that fails: wrong password/cancelled OS auth prompt, the privileged command itself exits with an error, or the process is terminated by a signal.","commonSituations":"User cancels the macOS/Windows UAC or polkit authentication dialog; setting system proxy requires admin rights and the user denies them; the underlying command (e.g. networksetup) fails on the target machine.","solutions":["Read the `output:` portion of the error message to see the real command failure.","Retry the operation and make sure the user completes the privilege prompt.","Verify the command string passed to sudo is valid on the platform (e.g. correct networksetup service name).","Handle ErrorKind::Other with a user-facing 'administrator privileges required' message instead of a raw error."],"exampleFix":"// before\nsudo(cmd)?;\n// after\nif let Err(e) = sudo(cmd) {\n    log::error!(\"privileged op failed: {e}\");\n    return Err(anyhow!(\"failed to apply system proxy (admin rights required): {e}\"));\n}","handlingStrategy":"try-catch","validationCode":"// cannot pre-validate user auth; verify command args before escalating\nassert!(!cmd.contains(\";\"), \"refusing to sudo compound command\");","typeGuard":null,"tryCatchPattern":"match sudo(cmd) {\n    Err(e) if e.kind() == std::io::ErrorKind::Other => report_admin_failure(&e.to_string()),\n    other => other?,\n}","preventionTips":["Explain to users why admin rights are needed before the prompt","Parse the 'output:' section of the error for the real cause","Validate platform-specific command args (e.g. networksetup service names) first"],"tags":["sudo","process","privileges","exit-code"],"backgroundTag":"command-failed","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}