mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
fix(windows): handle UV_UNKNOWN and UV_EAI_* error codes in libuv errno mapping (#25596)
## 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user