Replace c-ares status transmute with a checked from_repr conversion#31989
Replace c-ares status transmute with a checked from_repr conversion#31989robobun wants to merge 3 commits into
Conversation
|
Updated 1:05 AM PT - Jun 10th, 2026
❌ @robobun, your commit a1f84eb has 1 failures in
🧪 To try this PR locally: bunx bun-pr 31989That installs a local version of the PR into your bun-31989 --bun |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR refactors DNS error code handling for safety and adds validation tests. The ChangesDNS Error Code Handling
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
CI triage for build 61388: the two failures on the debian-13-x64-asan lane are unrelated to this diff.
The new DNS test passes locally on this branch (debug ASAN build and release). Not pushing a retrigger while #31797 is still failing on main; once that lands, a rerun here should go green. Auto-merge is already armed. |
|
Build 61388 finished. Final triage: every failure is accounted for and none involves this diff.
The new DNS test passed on every lane whose shard included it (alpine x64 and x64-baseline in this build), and locally on both the debug ASAN build and release. I am not pushing a retrigger: #31797 fails deterministically on all platforms, so a rerun cannot go green until #31820 lands. Auto-merge is armed, so once main is fixed, updating the branch or rerunning CI should merge this automatically. |
|
Update after the branch was brought up to date with main (which now skips bunx.test.ts, the #31797 blocker): Build 61658's only hard failure was Pushed one empty retrigger commit to re-roll. Auto-merge is armed, so a green run merges this automatically. |
|
CI status on build 61689: the single hard failure is Everything that failed in earlier builds is now green on this branch, including the napi isolate test and the asan lane; the new DNS test passes on every lane that ran it. I have already used my one retrigger, so I will not push again. A job-level retry of the failed debian-13-x64 job in Buildkite (or waiting for the next streams-leak-tolerant run) should go green; auto-merge is armed and will merge on a green run. |
What
Error::getinsrc/cares_sys/c_ares.rsconverted a c-ares status code to theErrorenum with a rangeassert!followed bymem::transmute::<i32, Error>. This PR derivesstrum::FromRepron the enum and uses the generatedError::from_reprinstead, removing theunsafeblock. This is the existing in-tree pattern for int-to-enum conversion (seesrc/errno/windows_errno.rs, which documents thatfrom_reprgenerates a checkedmatchover every declared discriminant).Why it is behavior-preserving
1..=ARES_ENOSERVER(1..=26), exactly the range the old assert admitted, sofrom_reprreturnsSomefor precisely the same inputs the transmute accepted.assert!with the same message.from_repris a generatedconst fnmatch; for a contiguous#[repr(i32)]enum this compiles to the same range check the assert already performed. This is a cold per-query error path in any case.Verification
cargo clippy -p bun_cares_sysclean,bun bdbuilds.test/js/node/dns/node-dns.test.js: a local UDP DNS server (no external network) answers queries with NXDOMAIN and SERVFAIL, and the test asserts the resolver surfacesENOTFOUNDandESERVFAILwithsyscall: "queryA"and the hostname set. Real Node v24.3.0 returns the same values for the same fixture. Because the change is behavior-preserving by design, this test passes before and after; it locks the c-ares status to error code mapping thatError::getowns.test-dns-channel-cancel.js,test-dns-channel-cancel-promise.js, andtest-dns-channel-timeout.js(ECANCELLED and ETIMEOUT through the same conversion) pass with the debug build.node-dns.test.jsshows 40 pass / 30 fail both on this branch and on an unmodified build in my environment; the 30 failures are tests that require external DNS, which this environment blocks.[daily-code-quality]