Repository navigation
Conversation
node-fetch starts every Response as "default" and only Response.error() sets "error". The shim returned "error" for any response that is not ok, so a fetched 404 or 500 looked like a network error. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: oven-sh/bun/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. Walkthrough
ChangesResponse Type Reporting
Suggested reviewers: Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The change reports the intended response types, with tests covering non-OK HTTP responses and native error responses. No material merge-readiness risk is evident. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to HTTP error responses will now report “default” rather than “error.” The reviewed change does not show a bypass of a security control, but applications outside this repository may rely on the previous value. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
…onse Response.redirect() now returns a node-fetch Response, and the old type getter reported "error" for any status that is not ok, so a 301 from Response.redirect() reported "error". Take the getter from oven-sh#43966: only a response that is natively "error" reports "error", as in node-fetch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
What does this PR do?
The builtin
node-fetchshim'sResponse.typereturned"error"for any response that is notok. So a fetched 404 or 500, ornew Response(body, { status: 404 }), reported"error". In node-fetch everyResponsestarts as"default", whatever its status. OnlyResponse.error()sets"error"(src/response.js#L38-L39,#L121-L125). Code that usesres.type === "error"to spot a network failure treated every HTTP error status as one.The fix is the one line in the
typegetter insrc/js/thirdparty/node-fetch.ts:return super.type === "error" ? "error" : "default";. A response that is natively"error"stays"error". Everything else is"default", as in node-fetch. This also covers the case where fetched responses get a spectypesuch as"basic"from the native side.How did you verify your code works?
New test in
test/js/node/http/node-fetch.test.js: "node-fetch Response.type is default for an HTTP error status". It checks constructed 404/500/200 responses, a fetched 404 from a localBun.serve({ port: 0 }), and a response that is natively"error". If the getter always returns"default", the test fails on that last case.Red on Bun 1.4.2:
I did not build Bun locally (no
bun bdon this machine), so the green half was checked by loading the patched module into Bun 1.4.2:USE_SYSTEM_BUN=1 bun test test/js/node/http/node-fetch.test.js -t "<new test>"with Bun 1.4.2 (744846f), whose builtinnode-fetchis the same as main at 29d9638 for these lines: fails with the output below.src/js/thirdparty/node-fetch.tsinto a user module and changes only the builtin-only syntax ($cpp(...)→ the globalResponse/Request/Blob/Headers/FormData/File,.$call→.call,$isJSArray→Array.isArray,new $Buffer→Buffer.from,Promise.$resolve→Promise.resolve, and aReadable.fromWebstand-in for_ReadableFromWeb). A--preloadthenmock.module("node-fetch", ...)s it, and the same test file runs against it. The new test fails on the transformed main source and passes on the transformed patched source. The rest of the file gives the same results before and after the patch. The 12 body-stream tests that fail under the stand-in fail the same way in both runs, because the stand-in is not_ReadableFromWeb.prettier --checkandoxlint --config=oxlint.jsonpass on the changed files.tsc --noEmit -p src/jsgives no new errors innode-fetch.ts.🤖 Generated with Claude Code