From f3fd7506efb4efc745e8d582ca32fe55b40e8440 Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Thu, 18 Dec 2025 21:41:41 -0800 Subject: [PATCH] fix(windows): handle UV_UNKNOWN and UV_EAI_* error codes in libuv errno mapping (#25596) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Add missing `UV_UNKNOWN` and `UV_EAI_*` error code mappings to the `errno()` function in `ReturnCode` - Fixes panic "integer does not fit in destination type" on Windows when libuv returns unmapped error codes - Speculative fix for BUN-131E ## Root Cause The `errno()` function was missing mappings for `UV_UNKNOWN` (-4094) and all `UV_EAI_*` address info errors (-3000 to -3014). When libuv returned these codes, the switch fell through to `else => null`, and the caller at `sys_uv.zig:317` assumed success and tried to cast the negative return code to `usize`, causing a panic. This was triggered in `readFileWithOptions` -> `preadv` when: - Memory-mapped file operations encounter exceptions (file modified/truncated by another process, network drive issues) - Windows returns error codes that libuv cannot map to standard errno values ## Crash Report ``` Bun v1.3.5 (1e86ceb) on windows x86_64baseline [] panic: integer does not fit in destination type sys_uv.zig:294: preadv node_fs.zig:5039: readFileWithOptions ``` ## Test plan - [ ] This fix prevents a panic, converting it to a proper error. Testing would require triggering `UV_UNKNOWN` from libuv, which is difficult to do reliably (requires memory-mapped file exceptions or unusual Windows errors). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 --- src/deps/libuv.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/deps/libuv.zig b/src/deps/libuv.zig index 7e8db2d0ab..2a116a0719 100644 --- a/src/deps/libuv.zig +++ b/src/deps/libuv.zig @@ -2880,6 +2880,21 @@ pub const ReturnCode = enum(c_int) { UV_ECANCELED => @intFromEnum(bun.sys.E.CANCELED), UV_ECHARSET => @intFromEnum(bun.sys.E.CHARSET), UV_EOF => @intFromEnum(bun.sys.E.EOF), + UV_UNKNOWN => @intFromEnum(bun.sys.E.UNKNOWN), + UV_EAI_ADDRFAMILY => @intFromEnum(bun.sys.E.UV_EAI_ADDRFAMILY), + UV_EAI_AGAIN => @intFromEnum(bun.sys.E.UV_EAI_AGAIN), + UV_EAI_BADFLAGS => @intFromEnum(bun.sys.E.UV_EAI_BADFLAGS), + UV_EAI_BADHINTS => @intFromEnum(bun.sys.E.UV_EAI_BADHINTS), + UV_EAI_CANCELED => @intFromEnum(bun.sys.E.UV_EAI_CANCELED), + UV_EAI_FAIL => @intFromEnum(bun.sys.E.UV_EAI_FAIL), + UV_EAI_FAMILY => @intFromEnum(bun.sys.E.UV_EAI_FAMILY), + UV_EAI_MEMORY => @intFromEnum(bun.sys.E.UV_EAI_MEMORY), + UV_EAI_NODATA => @intFromEnum(bun.sys.E.UV_EAI_NODATA), + UV_EAI_NONAME => @intFromEnum(bun.sys.E.UV_EAI_NONAME), + UV_EAI_OVERFLOW => @intFromEnum(bun.sys.E.UV_EAI_OVERFLOW), + UV_EAI_PROTOCOL => @intFromEnum(bun.sys.E.UV_EAI_PROTOCOL), + UV_EAI_SERVICE => @intFromEnum(bun.sys.E.UV_EAI_SERVICE), + UV_EAI_SOCKTYPE => @intFromEnum(bun.sys.E.UV_EAI_SOCKTYPE), else => null, } else