Compare commits

...

9 Commits

Author SHA1 Message Date
Meghan Denny
b28c5c3bbd Merge branch 'main' into nektro-patch-33435 2025-07-16 20:52:33 -08:00
Meghan Denny
cf48ebb236 Merge branch 'main' into nektro-patch-33435 2025-06-30 13:53:14 -08:00
Meghan Denny
2176bbefe8 address ci 2025-06-27 19:31:00 -07:00
nektro
8df32bcd27 bun run prettier 2025-06-27 21:46:34 +00:00
Meghan Denny
459c1d3bf5 Merge branch 'main' into nektro-patch-33435 2025-06-27 13:43:59 -08:00
Meghan Denny
1d19c05d61 address review 2025-06-24 21:55:23 -07:00
Meghan Denny
1be3e0b245 Merge remote-tracking branch 'origin/main' into nektro-patch-33435 2025-06-24 21:50:40 -07:00
Meghan Denny
9c2ffc8785 fix windows build 2025-06-23 21:35:46 -07:00
Meghan Denny
87c8fbd783 use type safety to ensure SystemError errno consistency 2025-06-23 20:29:13 -07:00
11 changed files with 35 additions and 42 deletions

View File

@@ -2414,7 +2414,7 @@ pub const DNSResolver = struct {
.result => |result| return result,
.err => |err| {
const system_error = JSC.SystemError{
.errno = -1,
.errno = @intFromEnum(bun.sys.SystemErrno.EPERM),
.code = bun.String.static(err.code()),
.message = bun.String.static(err.label()),
};
@@ -3075,7 +3075,7 @@ pub const DNSResolver = struct {
var channel: *c_ares.Channel = switch (this.getChannel()) {
.result => |res| res,
.err => |err| {
return globalThis.throwValue(err.toJSWithSyscall(globalThis, "query" ++ &[_]u8{std.ascii.toUpper(type_name[0])} ++ type_name[1..]));
return globalThis.throwValue(err.toJS(globalThis, "query" ++ &[_]u8{std.ascii.toUpper(type_name[0])} ++ type_name[1..]));
},
};
@@ -3120,7 +3120,7 @@ pub const DNSResolver = struct {
defer syscall.deref();
const system_error = JSC.SystemError{
.errno = -1,
.errno = @intFromEnum(bun.sys.SystemErrno.EPERM),
.code = bun.String.static(err.code()),
.message = bun.String.static(err.label()),
.syscall = syscall,

View File

@@ -312,7 +312,7 @@ pub fn NewSocket(comptime ssl: bool) type {
}
bun.assert(errno >= 0);
var errno_: c_int = if (errno == @intFromEnum(bun.sys.SystemErrno.ENOENT)) @intFromEnum(bun.sys.SystemErrno.ENOENT) else @intFromEnum(bun.sys.SystemErrno.ECONNREFUSED);
var errno_: c_uint = if (errno == @intFromEnum(bun.sys.SystemErrno.ENOENT)) @intFromEnum(bun.sys.SystemErrno.ENOENT) else @intFromEnum(bun.sys.SystemErrno.ECONNREFUSED);
const code_ = if (errno == @intFromEnum(bun.sys.SystemErrno.ENOENT)) bun.String.static("ENOENT") else bun.String.static("ECONNREFUSED");
if (Environment.isWindows and errno_ == @intFromEnum(bun.sys.SystemErrno.ENOENT)) errno_ = @intFromEnum(bun.sys.SystemErrno.UV_ENOENT);
if (Environment.isWindows and errno_ == @intFromEnum(bun.sys.SystemErrno.ECONNREFUSED)) errno_ = @intFromEnum(bun.sys.SystemErrno.UV_ECONNREFUSED);
@@ -320,7 +320,7 @@ pub fn NewSocket(comptime ssl: bool) type {
const callback = handlers.onConnectError;
const globalObject = handlers.globalObject;
const err = JSC.SystemError{
.errno = -errno_,
.errno = errno_,
.message = bun.String.static("Failed to connect"),
.syscall = bun.String.static("connect"),
.code = code_,

View File

@@ -2292,7 +2292,7 @@ pub fn spawnMaybeSync(
else
"";
var systemerror = bun.sys.Error.fromCode(if (err == error.EMFILE) .MFILE else .NFILE, .posix_spawn).withPath(display_path).toSystemError();
systemerror.errno = if (err == error.EMFILE) -bun.sys.UV_E.MFILE else -bun.sys.UV_E.NFILE;
systemerror.errno = if (err == error.EMFILE) bun.sys.UV_E.MFILE else bun.sys.UV_E.NFILE;
return globalThis.throwValue(systemerror.toErrorInstance(globalThis));
},
else => {
@@ -2310,7 +2310,7 @@ pub fn spawnMaybeSync(
"";
if (display_path.len > 0) {
var systemerror = err.withPath(display_path).toSystemError();
if (errno == .NOENT) systemerror.errno = -bun.sys.UV_E.NOENT;
if (errno == .NOENT) systemerror.errno = bun.sys.UV_E.NOENT;
return globalThis.throwValue(systemerror.toErrorInstance(globalThis));
}
},
@@ -2647,7 +2647,7 @@ fn throwCommandNotFound(globalThis: *JSC.JSGlobalObject, command: []const u8) bu
const err = JSC.SystemError{
.message = bun.String.createFormat("Executable not found in $PATH: \"{s}\"", .{command}) catch bun.outOfMemory(),
.code = bun.String.static("ENOENT"),
.errno = -bun.sys.UV_E.NOENT,
.errno = bun.sys.UV_E.NOENT,
.path = bun.String.cloneUTF8(command),
};
return globalThis.throwValue(err.toErrorInstance(globalThis));

View File

@@ -334,7 +334,7 @@ pub const UDPSocket = struct {
if (err != 0) {
const code = @tagName(bun.sys.SystemErrno.init(@as(c_int, @intCast(err))).?);
const sys_err = JSC.SystemError{
.errno = err,
.errno = @intCast(err),
.code = bun.String.static(code),
.message = bun.String.createFormat("bind {s} {s}", .{ code, config.hostname }) catch bun.outOfMemory(),
};

View File

@@ -6,7 +6,7 @@ const JSValue = JSC.JSValue;
const JSGlobalObject = JSC.JSGlobalObject;
pub const SystemError = extern struct {
errno: c_int = 0,
errno: c_uint = 0,
/// label for errno
code: String = .empty,
message: String, // it is illegal to have an empty message
@@ -29,7 +29,7 @@ pub const SystemError = extern struct {
pub fn getErrno(this: *const SystemError) bun.sys.E {
// The inverse in bun.sys.Error.toSystemError()
return @enumFromInt(this.errno * -1);
return @enumFromInt(this.errno);
}
pub fn deref(this: *const SystemError) void {

View File

@@ -19,7 +19,7 @@ pub const ZigException = extern struct {
runtime_type: JSRuntimeType,
/// SystemError only
errno: c_int = 0,
errno: c_uint = 0,
/// SystemError only
syscall: String = String.empty,
/// SystemError only

View File

@@ -2189,7 +2189,7 @@ JSC::EncodedJSValue SystemError__toErrorInstance(const SystemError* arg0, JSC::J
result->putDirect(vm, names.hostnamePublicName(), hostname, JSC::PropertyAttribute::DontDelete | 0);
}
result->putDirect(vm, names.errnoPublicName(), jsNumber(err.errno_), JSC::PropertyAttribute::DontDelete | 0);
result->putDirect(vm, names.errnoPublicName(), jsNumber(-static_cast<int>(err.errno_)), JSC::PropertyAttribute::DontDelete | 0);
ASSERT_NO_PENDING_EXCEPTION(globalObject);
return JSC::JSValue::encode(result);
@@ -2227,8 +2227,8 @@ JSC::EncodedJSValue SystemError__toErrorInstanceWithInfoObject(const SystemError
info->putDirect(vm, clientData->builtinNames().codePublicName(), jsString(vm, codeString), JSC::PropertyAttribute::DontDelete | 0);
info->putDirect(vm, vm.propertyNames->message, jsString(vm, messageString), JSC::PropertyAttribute::DontDelete | 0);
info->putDirect(vm, clientData->builtinNames().errnoPublicName(), jsNumber(err.errno_), JSC::PropertyAttribute::DontDelete | 0);
result->putDirect(vm, clientData->builtinNames().errnoPublicName(), jsNumber(err.errno_), JSC::PropertyAttribute::DontDelete | 0);
info->putDirect(vm, clientData->builtinNames().errnoPublicName(), jsNumber(-static_cast<int>(err.errno_)), JSC::PropertyAttribute::DontDelete | 0);
result->putDirect(vm, clientData->builtinNames().errnoPublicName(), jsNumber(-static_cast<int>(err.errno_)), JSC::PropertyAttribute::DontDelete | 0);
ASSERT_NO_PENDING_EXCEPTION(globalObject);
return JSC::JSValue::encode(result);

View File

@@ -128,7 +128,7 @@ typedef struct ErrorableResolvedSource {
} ErrorableResolvedSource;
typedef struct SystemError {
int errno_;
unsigned int errno_;
BunString code;
BunString message;
BunString path;
@@ -195,7 +195,7 @@ typedef struct ZigStackTrace {
typedef struct ZigException {
unsigned char type;
uint16_t runtime_type;
int errno_;
unsigned int errno_;
BunString syscall;
BunString system_code;
BunString path;

View File

@@ -302,8 +302,8 @@ pub fn getPriority(global: *JSC.JSGlobalObject, pid: i32) bun.JSError!i32 {
.message = bun.String.static("no such process"),
.code = bun.String.static("ESRCH"),
.errno = comptime switch (bun.Environment.os) {
else => -@as(c_int, @intFromEnum(std.posix.E.SRCH)),
.windows => libuv.UV_ESRCH,
else => @intFromEnum(std.posix.E.SRCH),
.windows => -libuv.UV_ESRCH,
},
.syscall = bun.String.static("uv_os_getpriority"),
};
@@ -657,7 +657,7 @@ fn networkInterfacesWindows(globalThis: *JSC.JSGlobalObject) bun.JSError!JSC.JSV
.message = bun.String.static("uv_interface_addresses failed"),
.code = bun.String.static("ERR_SYSTEM_ERROR"),
//.info = info,
.errno = err,
.errno = @intCast(-err),
.syscall = bun.String.static("uv_interface_addresses"),
};
return globalThis.throwValue(sys_err.toErrorInstance(globalThis));
@@ -825,8 +825,8 @@ pub fn setPriority1(global: *JSC.JSGlobalObject, pid: i32, priority: i32) !void
.message = bun.String.static("no such process"),
.code = bun.String.static("ESRCH"),
.errno = comptime switch (bun.Environment.os) {
else => -@as(c_int, @intFromEnum(std.posix.E.SRCH)),
.windows => libuv.UV_ESRCH,
else => @intFromEnum(std.posix.E.SRCH),
.windows => -libuv.UV_ESRCH,
},
.syscall = bun.String.static("uv_os_getpriority"),
};
@@ -837,8 +837,8 @@ pub fn setPriority1(global: *JSC.JSGlobalObject, pid: i32, priority: i32) !void
.message = bun.String.static("permission denied"),
.code = bun.String.static("EACCES"),
.errno = comptime switch (bun.Environment.os) {
else => -@as(c_int, @intFromEnum(std.posix.E.ACCES)),
.windows => libuv.UV_EACCES,
else => @intFromEnum(std.posix.E.ACCES),
.windows => -libuv.UV_EACCES,
},
.syscall = bun.String.static("uv_os_getpriority"),
};
@@ -849,8 +849,8 @@ pub fn setPriority1(global: *JSC.JSGlobalObject, pid: i32, priority: i32) !void
.message = bun.String.static("operation not permitted"),
.code = bun.String.static("EPERM"),
.errno = comptime switch (bun.Environment.os) {
else => -@as(c_int, @intFromEnum(std.posix.E.SRCH)),
.windows => libuv.UV_ESRCH,
else => @intFromEnum(std.posix.E.SRCH),
.windows => -libuv.UV_ESRCH,
},
.syscall = bun.String.static("uv_os_getpriority"),
};
@@ -897,19 +897,12 @@ pub fn totalmem() u64 {
}
pub fn uptime(global: *JSC.JSGlobalObject) bun.JSError!f64 {
_ = global;
switch (Environment.os) {
.windows => {
var uptime_value: f64 = undefined;
const err = libuv.uv_uptime(&uptime_value);
if (err != 0) {
const sys_err = JSC.SystemError{
.message = bun.String.static("failed to get system uptime"),
.code = bun.String.static("ERR_SYSTEM_ERROR"),
.errno = err,
.syscall = bun.String.static("uv_uptime"),
};
return global.throwValue(sys_err.toErrorInstance(global));
}
_ = libuv.uv_uptime(&uptime_value);
// uv_uptime cannot fail on windows
return uptime_value;
},
.mac => {

View File

@@ -1695,7 +1695,7 @@ pub const Error = enum(i32) {
pub fn reject(this: *Deferred, globalThis: *JSC.JSGlobalObject) void {
const system_error = JSC.SystemError{
.errno = @intFromEnum(this.errno),
.errno = @intCast(@intFromEnum(this.errno)),
.code = bun.String.static(this.errno.code()),
.message = if (this.hostname) |hostname|
bun.String.createFormat("{s} {s} {s}", .{ this.syscall, this.errno.code()[4..], hostname }) catch bun.outOfMemory()
@@ -1748,9 +1748,9 @@ pub const Error = enum(i32) {
return Deferred.init(this, syscall, host_string, promise.*);
}
pub fn toJSWithSyscall(this: Error, globalThis: *JSC.JSGlobalObject, comptime syscall: [:0]const u8) JSC.JSValue {
pub fn toJS(this: Error, globalThis: *JSC.JSGlobalObject, comptime syscall: [:0]const u8) JSC.JSValue {
const instance = (JSC.SystemError{
.errno = @intFromEnum(this),
.errno = @intCast(@intFromEnum(this)),
.code = bun.String.static(this.code()[4..]),
.syscall = bun.String.static(syscall),
.message = bun.String.createFormat("{s} {s}", .{ syscall, this.code()[4..] }) catch bun.outOfMemory(),
@@ -1761,7 +1761,7 @@ pub const Error = enum(i32) {
pub fn toJSWithSyscallAndHostname(this: Error, globalThis: *JSC.JSGlobalObject, comptime syscall: [:0]const u8, hostname: []const u8) JSC.JSValue {
const instance = (JSC.SystemError{
.errno = @intFromEnum(this),
.errno = @intCast(@intFromEnum(this)),
.code = bun.String.static(this.code()[4..]),
.message = bun.String.createFormat("{s} {s} {s}", .{ syscall, this.code()[4..], hostname }) catch bun.outOfMemory(),
.syscall = bun.String.static(syscall),

View File

@@ -540,7 +540,7 @@ pub const Error = struct {
pub fn toShellSystemError(this: Error) SystemError {
@setEvalBranchQuota(1_000_000);
var err = SystemError{
.errno = @as(c_int, this.errno) * -1,
.errno = this.errno,
.syscall = bun.String.static(@tagName(this.syscall)),
.message = .empty,
};
@@ -576,7 +576,7 @@ pub const Error = struct {
/// Use this whenever the error will be sent to JavaScript instead of the shell variant above.
pub fn toSystemError(this: Error) SystemError {
var err = SystemError{
.errno = -%@as(c_int, this.errno),
.errno = this.errno,
.syscall = bun.String.static(@tagName(this.syscall)),
.message = .empty,
};