{"record":{"id":"e8dfef7450789aac","repo":"tonhowtf/omniget","slug":"failed-to-open-deno-zip","errorCode":null,"errorMessage":"Failed to open Deno zip: {}","messagePattern":"Failed to open Deno zip: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/dependencies.rs","lineNumber":747,"sourceCode":"        .build()?;\n\n    let response = client.get(url).send().await?;\n    if !response.status().is_success() {\n        return Err(anyhow!(\n            \"Failed to download Deno: HTTP {}\",\n            response.status()\n        ));\n    }\n\n    let bytes = response.bytes().await?;\n    let data = bytes.to_vec();\n    let bin_dir_clone = bin_dir.clone();\n    let deno_name_clone = deno_name.clone();\n\n    tokio::task::spawn_blocking(move || {\n        let cursor = std::io::Cursor::new(&data);\n        let mut archive =\n            zip::ZipArchive::new(cursor).map_err(|e| anyhow!(\"Failed to open Deno zip: {}\", e))?;\n\n        for i in 0..archive.len() {\n            let mut file = archive\n                .by_index(i)\n                .map_err(|e| anyhow!(\"Failed to read zip entry: {}\", e))?;\n\n            let name = file.name().to_string();\n            if name.ends_with(&deno_name_clone) || name == \"deno\" || name == \"deno.exe\" {\n                let dest = bin_dir_clone.join(&deno_name_clone);\n                let mut buf = Vec::new();\n                std::io::Read::read_to_end(&mut file, &mut buf)?;\n                std::fs::write(&dest, &buf)?;\n                break;\n            }\n        }\n\n        Ok::<(), anyhow::Error>(())\n    })","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/dependencies.rs#L729-L765","documentation":"After downloading the Deno zip into memory, download_deno spawns a blocking task that wraps the bytes in an io::Cursor and opens it with zip::ZipArchive::new. If the byte buffer is not a valid zip (bad End-of-Central-Directory record, truncation, or an error page), the error 'Failed to open Deno zip' is returned.","triggerScenarios":"The HTTP body was actually an HTML/text error page or proxy block page saved as the zip; the response was truncated (connection dropped after status check); a redirect was followed to an HTML page.","commonSituations":"Captive portal or corporate proxy returning HTML; GitHub release asset moved/renamed so a redirect lands on an error page; partial download due to 300s timeout firing mid-body (though that usually errors earlier).","solutions":["Log the first bytes of `data` and verify the zip magic 'PK\\x03\\x04' before extraction","Check Content-Type and Content-Length headers match a binary zip before accepting the body","Re-run download_deno to get a fresh copy of the archive","Disable/bypass the intercepting proxy or configure correct proxy settings in http_client::apply_global_proxy","Increase the 300s timeout or stream to disk if network is slow and truncation is the cause"],"exampleFix":"// before\nlet cursor = std::io::Cursor::new(&data);\nlet mut archive =\n    zip::ZipArchive::new(cursor).map_err(|e| anyhow!(\"Failed to open Deno zip: {}\", e))?;\n// after\nif !data.starts_with(b\"PK\") {\n    let preview = String::from_utf8_lossy(&data[..data.len().min(200)]);\n    return Err(anyhow!(\"Downloaded Deno artifact is not a zip (got: {}) - check proxy/URL\", preview));\n}\nlet mut archive = zip::ZipArchive::new(std::io::Cursor::new(&data))\n    .map_err(|e| anyhow!(\"Failed to open Deno zip: {}\", e))?;","handlingStrategy":"validation","validationCode":"// after reading bytes, before extraction\nif !data.starts_with(b\"PK\\x03\\x04\") {\n    return Err(anyhow!(\"downloaded body is not a zip - check proxy/URL\"));\n}","typeGuard":"fn is_zip_bytes(data: &[u8]) -> bool {\n    data.starts_with(b\"PK\\x03\\x04\") && data.windows(4).rev().any(|w| w == b\"PK\\x05\\x06\")\n}","tryCatchPattern":"match download_deno().await {\n    Err(e) if e.to_string().contains(\"Failed to open Deno zip\") => {\n        eprintln!(\"Deno artifact invalid; clearing cache and retrying\");\n        // delete cached bytes/file, re-run ensure_js_runtime once\n        ensure_js_runtime().await?;\n    },\n    r => r?,\n}","preventionTips":["Validate the 'PK' magic bytes (and EOCD) before opening the archive","Check Content-Type/Content-Length of the download response","Re-download on failure instead of caching bad bytes","Bypass or correctly configure intercepting proxies that serve HTML error pages"],"tags":["zip","download","deno","corrupt-file"],"backgroundTag":"file-read-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}