{"record":{"id":"f2511181f389f043","repo":"Hmbown/CodeWhale","slug":"download-url-returned-status","errorCode":null,"errorMessage":"download {url} returned {status}","messagePattern":"download (.+?) returned (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/skills/install.rs","lineNumber":1159,"sourceCode":"    Bytes(Vec<u8>),\n    NotFound(reqwest::StatusCode),\n}\n\n/// Stream a URL into memory with a size cap. Aborts on the first read that\n/// would push the buffer over `max_size * 4` (the *4 accounts for compression;\n/// the unpack step still enforces `max_size` on the *uncompressed* bytes).\nasync fn download_with_cap(url: &str, max_size: u64) -> Result<DownloadAttempt> {\n    let resp = reqwest_client()\n        .get(url)\n        .send()\n        .await\n        .with_context(|| format!(\"failed to GET {url}\"))?;\n    let status = resp.status();\n    if !status.is_success() {\n        if status == reqwest::StatusCode::NOT_FOUND {\n            return Ok(DownloadAttempt::NotFound(status));\n        }\n        bail!(\"download {url} returned {status}\");\n    }\n    // Soft cap on the *compressed* download — well above max_size to allow\n    // for highly compressible payloads but still bounded.\n    let compressed_cap = max_size.saturating_mul(4);\n    let bytes = resp\n        .bytes()\n        .await\n        .with_context(|| format!(\"failed to read body of {url}\"))?;\n    if (bytes.len() as u64) > compressed_cap {\n        bail!(\"download {url} exceeds compressed size cap of {compressed_cap} bytes\");\n    }\n    Ok(DownloadAttempt::Bytes(bytes.to_vec()))\n}\n\nstruct StagedSkill {\n    skill_name: String,\n    staged_path: PathBuf,\n}","sourceCodeStart":1141,"sourceCodeEnd":1177,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/skills/install.rs#L1141-L1177","documentation":"`download_with_cap` performs the actual GET and bails on any non-success status, except 404 which is reported as `DownloadAttempt::NotFound` so callers can try the next candidate URL. Other failures (401, 403, 5xx) abort immediately with this error.","triggerScenarios":"The GET of a specific candidate URL returned e.g. 403 (private repo, rate limit) or 500; only 404 is tolerated and treated as try-next-URL.","commonSituations":"Downloading from a private GitHub repo without a token (403); registry/host rate limiting; transient 502/503 from a CDN; typo'd direct URL pointing at a protected path.","solutions":["Fix the underlying HTTP cause: add auth/token for private repos, wait out rate limits","Retry on transient 5xx with backoff","Provide an alternative direct tarball URL that is publicly reachable"],"exampleFix":"// before\nlet bytes = download_first_success(&[\"https://github.com/acme/priv/archive/refs/heads/main.tar.gz\"], &network, MAX).await?;\n// after — mirror to a public, token-free URL\nlet bytes = download_first_success(&[\"https://downloads.example.com/priv-main.tar.gz\"], &network, MAX).await?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match download_with_cap(url, &network, MAX).await {\n    Ok(DownloadAttempt::NotFound(status)) => try_next_url(),\n    Err(e) if e.to_string().contains(\"returned\") => {\n        if e.to_string().contains(\"500\") || e.to_string().contains(\"503\") { retry_with_backoff(); }\n    }\n    other => other?,\n}","preventionTips":["Authenticate private-repo downloads or mirror publicly","Handle 404 as fall-through to alternate URLs, other statuses as fatal","Monitor host rate limits before bulk installs"],"tags":["download","http","status"],"backgroundTag":"unexpected-http-status","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}