{"record":{"id":"128032ec02c988dd","repo":"libnyanpasu/clash-nyanpasu","slug":"flushing-the-system-dns-cache-is-not-supported-on","errorCode":null,"errorMessage":"flushing the system DNS cache is not supported on this platform","messagePattern":"flushing the system DNS cache is not supported on this platform","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/tauri/src/client/system_dns.rs","lineNumber":53,"sourceCode":"        .status()\n        .context(\"failed to request permission to flush the Windows DNS cache\")?;\n\n    ensure_success(status, \"ipconfig /flushdns\")\n}\n\n#[cfg(target_os = \"macos\")]\nfn flush_system_dns_cache() -> anyhow::Result<()> {\n    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<()> {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/client/system_dns.rs#L35-L71","documentation":"flush_system_dns_cache is a platform-gated helper that shells out to OS tools to clear the OS DNS resolver cache. On unsupported platforms (anything that is neither Windows nor macOS) the #[cfg] fallback deliberately aborts with this bail instead of attempting a command, because there is no portable way to flush DNS. Callers must treat DNS-cache flushing as a best-effort, platform-dependent capability.","triggerScenarios":"Calling flush_system_dns_cache() on a Linux/BSD or any non-Windows/non-macOS target; the cfg-gated stub compiles to an unconditional bail, so every call on such a platform fails immediately.","commonSituations":"Running nyanpasu on Linux and toggling system proxy/TUN in a flow that also tries to flush DNS; CI builds targeting unsupported platforms; distro-specific expectations that DNS can be flushed via systemd-resolved (not implemented here).","solutions":["Guard the call behind a cfg(all(windows, target_os = \"macos\")) check or an is_supported() predicate and skip flushing on other platforms","Log the failure as a warning and continue the calling flow (DNS flush is best-effort, not required for proxy correctness)","Optionally extend support by implementing Linux flush (e.g. resolvectl flush-caches) behind a new cfg arm"],"exampleFix":"// before\nflush_system_dns_cache()?;\n// after\n#[cfg(any(target_os = \"windows\", target_os = \"macos\"))]\nif let Err(e) = flush_system_dns_cache() {\n    log::warn!(\"DNS cache flush skipped: {e}\");\n}","handlingStrategy":"fallback","validationCode":"fn can_flush_dns() -> bool {\n    cfg!(any(target_os = \"windows\", target_os = \"macos\"))\n}","typeGuard":"fn dns_flush_supported() -> bool {\n    cfg!(any(target_os = \"windows\", target_os = \"macos\"))\n}","tryCatchPattern":"match flush_system_dns_cache() {\n    Err(e) if e.to_string().contains(\"not supported\") => log::info!(\"DNS flush unsupported; skipping\"),\n    other => other?,\n}","preventionTips":["Check platform capability before calling","Treat DNS flush as best-effort, never propagate as fatal","Log skipped flushes for diagnostics"],"tags":["dns","platform","rust"],"backgroundTag":"unsupported-platform","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"}