{"record":{"id":"6b380ca05fb34b62","repo":"denoland/deno","slug":"failed-to-receive-webassembly-content-http-status","errorCode":null,"errorMessage":"Failed to receive WebAssembly content: HTTP status code ${res.status}","messagePattern":"Failed to receive WebAssembly content: HTTP status code (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/fetch/26_fetch.js","lineNumber":1033,"sourceCode":"\n    // 2.3.\n    // The spec is ambiguous here, see\n    // https://github.com/WebAssembly/spec/issues/1138. The WPT tests expect\n    // the raw value of the Content-Type attribute lowercased. We ignore this\n    // for file:// because file fetches don't have a Content-Type.\n    if (!StringPrototypeStartsWith(res.url, \"file://\")) {\n      const contentType = res.headers.get(\"Content-Type\");\n      if (\n        typeof contentType !== \"string\" ||\n        StringPrototypeToLowerCase(contentType) !== \"application/wasm\"\n      ) {\n        throw new TypeError(\"Invalid WebAssembly content type\");\n      }\n    }\n\n    // 2.5.\n    if (!res.ok) {\n      throw new TypeError(\n        `Failed to receive WebAssembly content: HTTP status code ${res.status}`,\n      );\n    }\n\n    // Pass the resolved URL to v8.\n    op_wasm_streaming_set_url(rid, res.url);\n\n    if (res.body !== null) {\n      // 2.6.\n      // Rather than consuming the body as an ArrayBuffer, this feeds each chunk\n      // to the streaming compiler as soon as it's available. Instead of reading\n      // the body chunk-by-chunk in JS and calling `op_wasm_streaming_feed` once\n      // per chunk, hand the underlying stream resource to `op_pipe` with the\n      // wasm streaming resource as the sink (`WasmStreamingResource` implements\n      // `Resource::write`), so a single async op pumps the bytes straight into\n      // V8's streaming compiler.\n      const stream = res.body;\n      const resourceBacking = getReadableStreamResourceBacking(stream);","sourceCodeStart":1015,"sourceCodeEnd":1051,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/fetch/26_fetch.js#L1015-L1051","documentation":"After the Content-Type check, streaming WebAssembly compilation requires the fetch result to be a successful response. A non-ok status (4xx/5xx) means the body is likely an error page rather than a module, so a TypeError carrying the received status is thrown before feeding the streaming compiler.","triggerScenarios":"Module URL returns 404 (wrong path), 401/403 (auth-protected asset), or 500/502/503 (server or gateway failure) when passed to WebAssembly.instantiateStreaming/compileStreaming.","commonSituations":"Case-sensitive path mismatch on Linux servers; deployed assets missing after a partial release; reverse proxy serving HTML error pages for backend failures; expired auth tokens guarding static assets.","solutions":["Check res.ok and log res.status before compiling when you control the fetch","Fix the module URL (verify it with curl -I)","Resolve the server-side error or authentication so the asset returns 200","Handle non-ok statuses explicitly and only feed ok responses to the streaming compiler"],"exampleFix":"// before\nconst mod = await WebAssembly.compileStreaming(fetch(url)); // HTTP status code 404\n\n// after\nconst res = await fetch(url);\nif (!res.ok) throw new Error(`wasm fetch failed: ${res.status} ${res.url}`);\nconst mod = await WebAssembly.compileStreaming(Promise.resolve(res));","handlingStrategy":"validation","validationCode":"const res = await fetch(wasmUrl);\nif (!res.ok) {\n  throw new Error(`wasm module unavailable: ${res.status} ${res.statusText} for ${res.url}`);\n}\nconst mod = await WebAssembly.compileStreaming(Promise.resolve(res));","typeGuard":"function isOkWasmResponse(res: Response): boolean {\n  return res.ok && (res.headers.get(\"content-type\") ?? \"\").toLowerCase().startsWith(\"application/wasm\");\n}","tryCatchPattern":"try {\n  const mod = await WebAssembly.compileStreaming(fetch(url));\n} catch (err) {\n  if (err instanceof TypeError && /HTTP status code/.test(err.message)) {\n    // bad URL or server error: verify the URL, re-check auth/CDN, do not retry blindly\n  } else throw err;\n}","preventionTips":["Fetch the URL yourself and check res.ok before handing it to the streaming compiler","Verify asset URLs with curl -I in deployment pipelines","Watch for HTML error pages from gateways when a backend is down","Use res.url after redirects to confirm the final URL is the expected module"],"tags":["webassembly","http-status","fetch","streaming-compilation"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}