{"record":{"id":"9259ff445effd759","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-download-pac-script-status","errorCode":null,"errorMessage":"failed to download PAC script, status: {}","messagePattern":"failed to download PAC script, status: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/core/pac.rs","lineNumber":49,"sourceCode":"            .context(\"failed to build HTTP client\")?;\n\n        // Retry logic\n        let mut last_error = None;\n        for attempt in 1..=PAC_MAX_RETRIES {\n            match client.get(url).send().await {\n                Ok(response) => {\n                    if response.status().is_success() {\n                        match response.text().await {\n                            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            }","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/core/pac.rs#L31-L67","documentation":"download_pac_script checks response.status().is_success() before reading the body; this error is thrown when the server responds with a non-2xx HTTP status (404, 403, 500, etc.). The status code is embedded in the message, and the error is retried up to PAC_MAX_RETRIES before being returned as last_error.","triggerScenarios":"Calling download_pac_script when the configured PAC URL returns a non-success HTTP status — e.g. the script was deleted from the server (404), auth is required (401/403), or the server errors (5xx).","commonSituations":"PAC URL points to a moved/removed script; misconfigured web server or CDN returning errors; corporate proxy rejecting the request; server-side outage producing 5xx responses.","solutions":["Read the HTTP status in the message: 404 → fix the URL, 403/401 → fix auth, 5xx → wait/fix server","Verify the PAC URL in the app config is correct and reachable (open it in a browser or curl it)","Re-upload or restore the PAC script on the web server if it was removed","Check whether a corporate/ISP proxy intercepts and rejects the request","If the server is temporarily down, rely on the built-in retries or fix the URL to a stable mirror"],"exampleFix":"// before\nlet pac_url = \"http://old-server/proxy.pac\";\n// after\nlet pac_url = \"https://new-server/proxy.pac\"; // verify with curl -I before configuring","handlingStrategy":"retry","validationCode":"async fn pac_url_ok(url: &str) -> Result<(), String> {\n    let resp = reqwest::get(url).await.map_err(|e| e.to_string())?;\n    if resp.status().is_success() { Ok(()) } else { Err(format!(\"status {}\", resp.status())) }\n}","typeGuard":null,"tryCatchPattern":"match download_pac_script().await {\n    Ok(script) => install(script),\n    Err(e) if e.to_string().contains(\"status: 404\") => log::error!(\"PAC script missing on server; fix URL\"),\n    Err(e) => log::warn!(\"PAC download failed: {e}\"),\n}","preventionTips":["Verify the PAC URL returns 200 before configuring it in the app","Pin PAC scripts to stable URLs with redirects handled server-side","Add server-side monitoring/uptime checks for the PAC endpoint","Avoid URLs behind expiring tokens or auth walls"],"tags":["http","network","pac","proxy"],"backgroundTag":"http-non-2xx-response","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"}