{"record":{"id":"85681869f620bec2","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-download-pac-script","errorCode":null,"errorMessage":"failed to download PAC script: {}","messagePattern":"failed to download PAC script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/core/pac.rs","lineNumber":58,"sourceCode":"                            Ok(content) => return Ok(content),\n                            Err(e) => {\n                                let err =\n                                    anyhow::anyhow!(\"failed to read PAC script content: {}\", e);\n                                log::warn!(target: \"app\", \"Attempt {}/{} failed: {}\", attempt, PAC_MAX_RETRIES, err);\n                                last_error = Some(err);\n                            }\n                        }\n                    } else {\n                        let err = anyhow::anyhow!(\n                            \"failed to download PAC script, status: {}\",\n                            response.status()\n                        );\n                        log::warn!(target: \"app\", \"Attempt {}/{} failed: {}\", attempt, PAC_MAX_RETRIES, err);\n                        last_error = Some(err);\n                    }\n                }\n                Err(e) => {\n                    let err = anyhow::anyhow!(\"failed to download PAC script: {}\", e);\n                    log::warn!(target: \"app\", \"Attempt {}/{} failed: {}\", attempt, PAC_MAX_RETRIES, err);\n                    last_error = Some(err);\n                }\n            }\n\n            // Wait before retrying (except on last attempt)\n            if attempt < PAC_MAX_RETRIES {\n                tokio::time::sleep(Duration::from_secs(PAC_RETRY_DELAY)).await;\n            }\n        }\n\n        Err(last_error.unwrap_or_else(|| {\n            anyhow::anyhow!(\n                \"failed to download PAC script after {} attempts\",\n                PAC_MAX_RETRIES\n            )\n        }))\n    }","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/core/pac.rs#L40-L76","documentation":"download_pac_script uses a reqwest client to GET the PAC URL; this error is thrown when the request itself fails at the transport level (DNS resolution failure, connection refused/timeout, TLS error). It is logged per-attempt and stored as last_error, retried up to PAC_MAX_RETRIES times with PAC_RETRY_DELAY between attempts.","triggerScenarios":"Calling download_pac_script when reqwest's .send() returns Err — hostname not resolvable, server unreachable, connection reset, TLS handshake failure, or request timeout.","commonSituations":"PAC URL uses a hostname that no longer resolves; firewall blocks outbound access; server offline; TLS certificate expired or untrusted; system has no network connectivity at startup.","solutions":["Check network connectivity and DNS resolution of the PAC URL host (ping/nslookup)","Verify the PAC URL scheme and host are correct (http vs https, no typos)","Check for expired TLS certificates if using HTTPS (curl -v the URL)","Confirm firewall/VPN/corporate proxy is not blocking the connection","Rely on the fallback: update_pac() falls back to direct proxy when PAC download fails"],"exampleFix":"// before\npac_url = \"https://pac.internal.lan/proxy.pac\"\n// after\npac_url = \"https://pac.example.com/proxy.pac\" // reachable, DNS-resolvable host","handlingStrategy":"retry","validationCode":"fn pac_host_resolvable(url: &str) -> bool {\n    url::Url::parse(url).ok()\n        .and_then(|u| u.host_str().map(|h| std::net::ToSocketAddrs::to_socket_addrs(&(h, u.port_or_known_default())).is_ok()))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match download_pac_script().await {\n    Ok(script) => install(script),\n    Err(e) if e.to_string().contains(\"failed to download PAC script\") => {\n        log::warn!(\"transport failure ({e}); checking connectivity before retry\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Use IP-stable, DNS-reliable hosts for PAC URLs","Prefer HTTPS with valid certificates","Check firewall rules allow outbound access to the PAC host","Validate DNS resolution during deployment/setup"],"tags":["network","dns","pac","proxy","tls"],"backgroundTag":"network-request-failed","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"}