{"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":1034,"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":1016,"sourceCodeEnd":1052,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/fetch/26_fetch.js#L1016-L1052","documentation":"After the Content-Type check, Deno's streaming WebAssembly compile verifies res.ok (status 200-299). A non-2xx reply (404, 401, 403, 500, an HTML error page) is not valid WebAssembly, so instantiateStreaming/compileStreaming throws a TypeError that includes the exact HTTP status received.","triggerScenarios":"WebAssembly.instantiateStreaming(fetch(url)) where the server returns 404 (wrong path), 401/403 (authentication required by a gateway), 500, or a redirect chain ending in an error page.","commonSituations":"Deployed asset paths wrong after hashed filenames changed between releases; CDN access tokens expired; missing credentials: 'include' so the gateway returns 401; reverse proxy serving a maintenance page.","solutions":["Check res.ok (or res.status) before passing the response to the streaming API","Fix the URL / asset manifest to point at the real .wasm file","Send the credentials or headers the endpoint requires (fetch(url, { credentials: 'include' }))","Debug once by reading await res.text() of the failing response to see the error page"],"exampleFix":"// before\nconst { instance } = await WebAssembly.instantiateStreaming(fetch(url));\n\n// after\nconst res = await fetch(url);\nif (!res.ok) throw new Error(`wasm fetch failed: ${res.status}`);\nconst { instance } = await WebAssembly.instantiateStreaming(res);","handlingStrategy":"validation","validationCode":"const res = await fetch(url);\nif (!res.ok) {\n  throw new Error(`wasm asset fetch failed: ${res.status} ${url}`);\n}\nconst mod = await WebAssembly.instantiateStreaming(res);","typeGuard":null,"tryCatchPattern":"try {\n  mod = await WebAssembly.instantiateStreaming(res);\n} catch (err) {\n  if (err instanceof TypeError && /HTTP status code/.test(err.message)) {\n    // wrong URL or auth: surface a clear deployment error\n  } else throw err;\n}","preventionTips":["Always check res.ok before streaming a response into WebAssembly","Load wasm paths from an asset manifest instead of hardcoding them","Include required credentials/headers on protected CDNs"],"tags":["webassembly","fetch","http-status"],"backgroundTag":"http-error-status","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}