{"record":{"id":"10dd5d4666ed4f6e","repo":"santifer/career-ops","slug":"could-not-download-the-index-http-res-status","errorCode":null,"errorMessage":"could not download the index (HTTP ${res.status}): ${url}","messagePattern":"could not download the index \\(HTTP (.+?)\\): (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/install-h1b-index.mjs","lineNumber":146,"sourceCode":"  // Recorded, never acted on, so a missing or odd value costs a label rather\n  // than the install. Bounded because it lands in a file on disk.\n  const version = doc.version === undefined || doc.version === null\n    ? null\n    : String(doc.version).slice(0, 64);\n  return { filename, sha256, version };\n}\n\n/**\n * Stream the asset to `tmpFile`, hashing as it goes, and return the digest.\n *\n * Streamed rather than buffered: the body is millions of times the size of\n * anything else this plugin reads, and readBoundedText's 1 MiB ceiling exists\n * precisely because nothing on the API path should ever be this big. Hashing\n * during the write means the file is never read a second time to verify it.\n */\nasync function downloadAsset(fetchImpl, url, tmpFile) {\n  return fetchImpl(url, { timeoutMs: ASSET_TIMEOUT_MS }, async res => {\n    if (res.status !== 200) throw new Error(`could not download the index (HTTP ${res.status}): ${url}`);\n    const declared = Number(res.headers?.get?.('content-length'));\n    if (Number.isFinite(declared) && declared > MAX_INDEX_BYTES) {\n      throw new Error(`the published index exceeds ${MAX_INDEX_BYTES} bytes (${declared}): ${url}`);\n    }\n    if (!res.body || typeof res.body.getReader !== 'function') {\n      throw new Error(`the index response carried no readable body: ${url}`);\n    }\n\n    const hash = createHash('sha256');\n    const out = createWriteStream(tmpFile);\n    // A write failure (disk full, an unwritable target) arrives as an 'error'\n    // event on the stream, and an EventEmitter error with no listener is an\n    // uncaughtException: the CLI died on a stack trace instead of returning\n    // the envelope, and the cleanup that removes the partial .tmp file never\n    // ran. Recording the error here makes the crash impossible; the checks\n    // below turn it into the ordinary failure it is. once(out, 'drain') needs\n    // no extra wiring, it already rejects when 'error' fires mid-wait.\n    let writeError = null;","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/h1b-sponsor/install-h1b-index.mjs#L128-L164","documentation":"downloadAsset throws this when the HTTP fetch of the H1B index asset returns any status other than 200. The installer refuses to persist a non-OK response (404, 403, 500, redirects not followed, etc.) as the index file. It is a guard against silently installing an error page or empty body as the published index.","triggerScenarios":"install-h1b-index.mjs calls downloadAsset(fetchImpl, url, tmpFile); the callback receives a Response whose res.status !== 200. Any non-200 on the index download URL produces this error, including 404 (asset moved), 403 (rate-limit/blocked), and 5xx (server error).","commonSituations":"The upstream index URL changed or the release asset was removed; a CDN/proxy returns 403 to the plugin's user-agent; the endpoint is temporarily down (502/503); a custom ASSET base URL is misconfigured.","solutions":["Re-run the installer; transient 5xx/429 often resolve on retry (wait briefly if rate-limited).","Check the URL printed in the error manually (curl -I) to confirm whether the asset still exists.","Update the plugin or its configured index URL if the asset has moved to a new release.","Check corporate proxy/VPN interference if every asset returns 403."],"exampleFix":"// before\ncallback(res) { /* assumes res is OK */ }\n// after\ncallback(res) {\n  if (res.status === 429 || res.status >= 500) return retryLater();\n  if (res.status !== 200) throw new Error(`index download failed: HTTP ${res.status} for ${url}`);\n}","handlingStrategy":"retry","validationCode":"const head = await fetch(url, { method: 'HEAD' });\nif (head.status !== 200) console.warn(`index asset not available: HTTP ${head.status}; retry later or check the URL`);","typeGuard":null,"tryCatchPattern":"try {\n  await installIndex();\n} catch (e) {\n  if (e.message.includes('could not download the index')) {\n    const status = e.message.match(/HTTP (\\d+)/)?.[1];\n    if (status === '429' || status?.startsWith('5')) await sleep(5000).then(retry);\n    else console.error(`asset unavailable (${status}); check the URL or update the plugin`);\n  }\n}","preventionTips":["curl -I the index URL before automating installs to confirm it returns 200.","Pin to a known-good release/tag of the index asset.","Add exponential backoff around the installer for transient 5xx/429."],"tags":["network","http","download"],"backgroundTag":"http-non-200-response","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}