{"record":{"id":"3a9074c9dbea0301","repo":"santifer/career-ops","slug":"the-index-response-carried-no-readable-body-url","errorCode":null,"errorMessage":"the index response carried no readable body: ${url}","messagePattern":"the index response carried no readable body: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/install-h1b-index.mjs","lineNumber":152,"sourceCode":"}\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;\n    out.on('error', err => { writeError = err; });\n    const reader = res.body.getReader();\n    let total = 0;\n    try {\n      for (;;) {\n        if (writeError) {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/h1b-sponsor/install-h1b-index.mjs#L134-L170","documentation":"downloadAsset throws this when the fetch Response has no body or its body does not expose getReader(), so the index cannot be streamed. The installer requires a WHATWG-streams-compatible response body to hash-while-writing.","triggerScenarios":"downloadAsset's fetchImpl returns a response where res.body is null/undefined or lacks a getReader function — e.g. a stubbed fetch in tests, an undici Response consumed already, or a non-standard fetch implementation.","commonSituations":"Custom fetchImpl injection (tests, proxies) returning an incomplete Response mock; a fetch polyfill without stream support; calling downloadAsset twice on the same Response (body already consumed/nullified).","solutions":["If you inject a fetchImpl, return a Response with a real ReadableStream body (e.g. new Response(readableStream)).","Use a fetch implementation with streams support (undici / Node >= 18 built-in fetch), not a text-only polyfill.","Do not reuse an already-consumed Response object; refetch instead."],"exampleFix":"// before\nfetchImpl: async (url) => ({ status: 200, headers: new Map(), text: async () => data })\n// after\nfetchImpl: async (url) => new Response(ReadableStream.from([Buffer.from(data)]), { status: 200 })","handlingStrategy":"type-guard","validationCode":"if (typeof fetchImpl !== 'function') throw new Error('fetchImpl must be a function');\nconst probe = await fetchImpl(url, {});\nif (!probe.body || typeof probe.body.getReader !== 'function') throw new Error('fetch impl must return a streaming Response body');","typeGuard":"function hasStreamBody(res) {\n  return !!res && !!res.body && typeof res.body.getReader === 'function';\n}","tryCatchPattern":"try {\n  await installIndex();\n} catch (e) {\n  if (e.message.includes('no readable body')) {\n    console.error('Your injected fetch/polyfill lacks stream support; use undici or Node built-in fetch.');\n  }\n}","preventionTips":["Test any custom fetchImpl against downloadAsset in CI before relying on it.","Use Node >= 18 built-in fetch (undici) which always provides a ReadableStream body.","Never reuse a consumed Response object."],"tags":["streaming","fetch","validation"],"backgroundTag":"unexpected-response-shape","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"}