{"record":{"id":"537b294d8714347f","repo":"libnyanpasu/clash-nyanpasu","slug":"operation-failed-with-status-status","errorCode":null,"errorMessage":"{operation} failed with status {status}","messagePattern":"(.+?) failed with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/client/system_dns.rs","lineNumber":61,"sourceCode":"    let status = std::process::Command::new(\"/usr/bin/osascript\")\n        .args([\"-e\", MACOS_SCRIPT])\n        .status()\n        .context(\"failed to request permission to flush the macOS DNS cache\")?;\n\n    ensure_success(status, \"macOS DNS cache flush\")\n}\n\n#[cfg(not(any(target_os = \"windows\", target_os = \"macos\")))]\nfn flush_system_dns_cache() -> anyhow::Result<()> {\n    anyhow::bail!(\"flushing the system DNS cache is not supported on this platform\")\n}\n\n#[cfg(any(target_os = \"windows\", target_os = \"macos\"))]\nfn ensure_success(status: std::process::ExitStatus, operation: &str) -> anyhow::Result<()> {\n    if status.success() {\n        Ok(())\n    } else {\n        anyhow::bail!(\"{operation} failed with status {status}\")\n    }\n}\n\n#[cfg(test)]\n#[derive(Debug, Default)]\npub struct NoopSystemDnsCache;\n\n#[cfg(test)]\nimpl SystemDnsCache for NoopSystemDnsCache {\n    fn flush(&self) -> anyhow::Result<()> {\n        Ok(())\n    }\n}\n\n#[cfg(all(test, target_os = \"windows\"))]\nmod windows_tests {\n    use super::{WINDOWS_ARGS, WINDOWS_PROGRAM};\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/client/system_dns.rs#L43-L79","documentation":"ensure_success maps a child process's non-zero exit status into an anyhow error, naming the operation performed (e.g. 'macOS DNS cache flush'). It fires when the spawned OS command (ipconfig /flushdns on Windows, dscacheutil/killall on macOS) exits non-zero. It only reports the raw ExitStatus — the command's stderr is not included, which can make diagnosis harder.","triggerScenarios":"flush_system_dns_cache spawns the platform flush command and it exits with a non-zero status; e.g. ipconfig /flushdns fails due to restricted permissions, or the macOS command is missing/blocked.","commonSituations":"Running without sufficient privileges in service contexts; hardened/minimal OS images missing dscacheutil or ipconfig; antivirus or sandbox blocking command execution.","solutions":["Re-run the operation from an elevated/privileged context (the flush commands typically need none, but sandboxed/service contexts may block process spawning)","Capture and include the child process stderr in the error message to identify the real cause","Check the platform command exists (which/where) and handle a missing binary distinctly from a failed run","Treat as best-effort: log and continue, since a stale DNS cache rarely blocks operation"],"exampleFix":"// before\nanyhow::bail!(\"{operation} failed with status {status}\")\n// after\nanyhow::bail!(\"{operation} failed with status {status}: {stderr}\")","handlingStrategy":"try-catch","validationCode":"// ensure the platform command exists before spawning\n// e.g. `where ipconfig` on Windows, `which dscacheutil` on macOS","typeGuard":null,"tryCatchPattern":"if let Err(e) = flush_system_dns_cache() {\n    log::warn!(\"DNS cache flush failed (non-fatal): {e}\");\n}","preventionTips":["Capture child stderr and include it in errors","Run from a context allowed to spawn system commands","Treat as best-effort side effect"],"tags":["dns","process","exit-status"],"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"}