Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig: make throwPretty use JSError #15410

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,13 @@ pub const JSBundler = struct {
defer path.deinit();

var dir = std.fs.cwd().openDir(path.slice(), .{}) catch |err| {
globalThis.throwPretty("{s}: failed to open root directory: {s}", .{ @errorName(err), path.slice() });
return error.JSError;
return globalThis.throwPretty("{s}: failed to open root directory: {s}", .{ @errorName(err), path.slice() });
};
defer dir.close();

var rootdir_buf: bun.PathBuffer = undefined;
const rootdir = bun.getFdPath(bun.toFD(dir.fd), &rootdir_buf) catch |err| {
globalThis.throwPretty("{s}: failed to get full root directory path: {s}", .{ @errorName(err), path.slice() });
return error.JSError;
return globalThis.throwPretty("{s}: failed to get full root directory path: {s}", .{ @errorName(err), path.slice() });
};
try this.rootdir.appendSliceExact(rootdir);
}
Expand Down
5 changes: 2 additions & 3 deletions src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5330,7 +5330,7 @@ pub const ServerWebSocket = struct {
callframe: *JSC.CallFrame,
comptime name: string,
comptime opcode: uws.Opcode,
) JSValue {
) bun.JSError!JSValue {
const args = callframe.arguments_old(2);

if (this.isClosed()) {
Expand Down Expand Up @@ -5377,8 +5377,7 @@ pub const ServerWebSocket = struct {
},
}
} else {
globalThis.throwPretty("{s} requires a string or BufferSource", .{name});
return .zero;
return globalThis.throwPretty("{s} requires a string or BufferSource", .{name});
}
}
}
Expand Down
27 changes: 7 additions & 20 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3303,37 +3303,24 @@ pub const JSGlobalObject = opaque {
return err;
}

pub fn throw(
this: *JSGlobalObject,
comptime fmt: [:0]const u8,
args: anytype,
) void {
pub fn throw(this: *JSGlobalObject, comptime fmt: [:0]const u8, args: anytype) void {
const instance = this.createErrorInstance(fmt, args);
if (instance != .zero)
this.vm().throwError(this, instance);
bun.assert(instance != .zero);
this.vm().throwError(this, instance);
}

pub fn throw2(
this: *JSGlobalObject,
comptime fmt: [:0]const u8,
args: anytype,
) JSError {
pub fn throw2(this: *JSGlobalObject, comptime fmt: [:0]const u8, args: anytype) JSError {
const instance = this.createErrorInstance(fmt, args);
bun.assert(instance != .zero);
return this.vm().throwError2(this, instance);
}

pub fn throwPretty(
this: *JSGlobalObject,
comptime fmt: [:0]const u8,
args: anytype,
) void {
pub fn throwPretty(this: *JSGlobalObject, comptime fmt: [:0]const u8, args: anytype) bun.JSError {
const instance = switch (Output.enable_ansi_colors) {
inline else => |enabled| this.createErrorInstance(Output.prettyFmt(fmt, enabled), args),
};

if (instance != .zero)
this.vm().throwError(this, instance);
bun.assert(instance != .zero);
return this.vm().throwError2(this, instance);
}
extern fn JSC__JSGlobalObject__queueMicrotaskCallback(*JSGlobalObject, *anyopaque, Function: *const (fn (*anyopaque) callconv(.C) void)) void;
pub fn queueMicrotaskCallback(
Expand Down
Loading