Compare commits

...

2 Commits

Author SHA1 Message Date
Jarred Sumner
e01cea927b Update sys.zig 2024-08-12 20:44:31 -07:00
Jarred Sumner
01d5d1707b Make the error when udpSocket creation fails better 2024-08-12 20:28:55 -07:00
2 changed files with 12 additions and 1 deletions

View File

@@ -330,7 +330,11 @@ pub const UDPSocket = struct {
)) |socket| {
this.socket = socket;
} else {
globalThis.throw("Failed to bind socket", .{});
if (bun.sys.Error.fromLibcErrno(.bind)) |err| {
globalThis.throwValue(err.toJSC(globalThis));
} else {
globalThis.throwError("Failed to bind socket", .{});
}
return .zero;
}

View File

@@ -225,6 +225,7 @@ pub const Tag = enum(u8) {
pidfd_open,
poll,
watch,
bind,
kevent,
kqueue,
@@ -297,6 +298,12 @@ pub const Error = struct {
return copy;
}
pub fn fromLibcErrno(syscall: Syscall.Tag) ?Error {
const errno = bun.C.getErrno(@as(i32, -1));
if (errno == .SUCCESS) return null;
return .{ .errno = @intFromEnum(errno), .syscall = syscall };
}
pub fn fromCode(errno: E, syscall: Syscall.Tag) Error {
return .{
.errno = @as(Int, @intCast(@intFromEnum(errno))),