GeezerVison is showing github.com — types: UDP error handlers take the failure as their only argument by abdullahtas0 · Pull Request #46251 · oven-sh/bun
Conversation
What does this PR do?
Fixes #46052.
Bun.udpSocket calls the error handler with the socket as this and the failure as the only argument (call_error_handler passes [err]). node:dgram already depends on that shape (error: error => ..., including error.errqueue and error.syscall). The declarations said error(socket, error), so a handler written from the types received the SystemError as the socket and undefined as the error, and a handler that matched the runtime failed to type-check (err.code was read off Socket).
Bun.udp.SocketHandler and ConnectedSocketHandler now declare error(this: socket, error: SocketError).
SocketError is the system error the receive path builds (code, errno, syscall), plus Linux errqueue when the errno came from MSG_ERRQUEUE. Exceptions thrown by data or drain are still forwarded on this same argument.
- The connected
udpSocket overload is declared first. Overload contextual typing uses the first match, and connect is required there, so a connected literal types this as ConnectedSocket. An unconnected literal skips it.
- Docs show the one-argument form. Existing UDP tests that rejected with the second argument (always
undefined) now use the argument the runtime actually passes.
How did you verify your code works?
- Runtime, Bun 1.4.3 on macOS arm64, connected socket to
127.0.0.1:9: this === socket, one argument, code: "ECONNREFUSED", syscall: "recv", errno: -61.
bun test test/integration/bun-types/bun-types.test.ts: 24 pass. That covers the fixture with and without lib.dom, with no lib, exactOptionalPropertyTypes, TypeScript 6.0.2, TypeScript 7.0.2, and TypeScript 7.1. The fixture checks this, SocketError (code, errno, syscall, errqueue), the arrow form node:dgram uses, and that a second parameter is rejected.
bun test test/js/bun/udp/udp_socket_recv_flags.test.ts and the binaryType cases in udp_socket.test.ts on Bun 1.4.3: pass. The Linux ICMP case is skipped on macOS, same as before. This patch does not change the runtime.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Bun.udpSocket already calls `error` with the socket as `this` and the
failure as the sole argument. The declarations said `(socket, error)`,
so code written from the types read `undefined` instead of the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude Code Review
This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Repository: oven-sh/bun/.coderabbit.yaml
- Review profile: ASSERTIVE
- Plan: Advanced
- Run ID:
5d2e2716-ce66-49df-8518-d492e0b71677
📥 Commits
-
Reviewing files that changed from the base of the PR and between 9b4284f and e9fee63.
📒 Files selected for processing: 5
-
docs/runtime/networking/udp.mdx
packages/bun-types/bun.d.ts
test/integration/bun-types/fixture/udp.ts
test/js/bun/udp/udp_socket.test.ts
test/js/bun/udp/udp_socket_recv_flags.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Walkthrough
UDP error handler types now match the runtime’s single-error-argument callback contract, with the socket available as this. The change adds a public udp.SocketError type, documents the callback, and adds type and JavaScript test coverage.
Changes
UDP error callback contract
| Layer / File(s) |
Summary |
Define the UDP error callback contract packages/bun-types/bun.d.ts |
Adds udp.SocketError with optional Linux errqueue metadata. Both UDP handler types use the socket as this and accept SocketError as their only argument. The connected udpSocket overload now precedes the unconnected overload. |
Document and validate the callback contract docs/runtime/networking/udp.mdx, test/integration/bun-types/fixture/udp.ts, test/js/bun/udp/udp_socket.test.ts, test/js/bun/udp/udp_socket_recv_flags.test.ts |
Documents callback context and error fields. Adds type coverage for unconnected, uint8array, and connected sockets, and updates JavaScript test callbacks to accept one error argument. |
Suggested reviewers: robobun
Priority: ➖ Normal
Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to e9fee
-
This change aligns the UDP error handler types and docs with how the runtime already calls the handler. It has no runtime effect and no actionable merge risk was found.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title clearly and concisely describes the main change: UDP error handlers now receive the failure as their only argument. |
| Description check |
 |
The description includes both required sections. It explains the type changes, runtime behavior, affected overloads, documentation updates, and verification results. |
| Linked Issues check |
 |
Issue #46052 requires the UDP error callback types to match runtime behavior: the failure is the only argument and the socket is this. The declarations now use `error(this: Socket..., error: SocketE… |
| Out of Scope Changes check |
 |
The changes stay within issue #46052. The documentation explains the corrected callback contract. The type fixture validates the public declarations. Existing UDP tests update callbacks to use the run… |
Full details: Linked Issues check
-
Explanation
Issue #46052 requires the UDP error callback types to match runtime behavior: the failure is the only argument and the socket is this. The declarations now use error(this: Socket..., error: SocketError) and the connected equivalent. SocketError exposes the documented system-error fields and Linux errqueue. The connected overload is first so contextual typing selects ConnectedSocket. Type fixtures cover connected and unconnected callbacks, arrow callbacks, error fields, and rejection of a second callback parameter. Existing runtime tests now consume the actual argument.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue #46052. The documentation explains the corrected callback contract. The type fixture validates the public declarations. Existing UDP tests update callbacks to use the runtime argument and preserve their existing behavior. No unrelated implementation or runtime change is present.
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
-
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Buildkite build 129693 is still blocked, so CI has not run on this fork. Could a maintainer unblock it?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Reviewers
alii
Awaiting requested review from alii
alii is a code owner
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|