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 throw use JSError #15444

Merged
merged 6 commits into from
Dec 2, 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
2 changes: 1 addition & 1 deletion src/bake/DevServer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ pub fn init(options: Options) bun.JSOOM!*DevServer {
dev.framework = dev.framework.resolve(&dev.server_bundler.resolver, &dev.client_bundler.resolver, options.arena) catch {
if (dev.framework.is_built_in_react)
try bake.Framework.addReactInstallCommandNote(&dev.log);
return global.throwValue2(dev.log.toJSAggregateError(global, "Framework is missing required files!"));
return global.throwValue(dev.log.toJSAggregateError(global, "Framework is missing required files!"));
};

errdefer dev.route_lookup.clearAndFree(allocator);
Expand Down
5 changes: 2 additions & 3 deletions src/bake/FrameworkRouter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ pub const JSFrameworkRouter = struct {
}),
);
}
return global.throwValue2(global.createAggregateErrorWithArray(
return global.throwValue(global.createAggregateErrorWithArray(
bun.String.static("Errors scanning routes"),
arr,
));
Expand Down Expand Up @@ -1255,8 +1255,7 @@ pub const JSFrameworkRouter = struct {
var log = TinyLog.empty;
const parsed = style.parse(filepath.slice(), std.fs.path.extension(filepath.slice()), &log, true, alloc) catch |err| switch (err) {
error.InvalidRoutePattern => {
global.throw("{s} ({d}:{d})", .{ log.msg.slice(), log.cursor_at, log.cursor_len });
return error.JSError;
return global.throw("{s} ({d}:{d})", .{ log.msg.slice(), log.cursor_at, log.cursor_len });
},
else => |e| return e,
} orelse
Expand Down
2 changes: 1 addition & 1 deletion src/bake/bake.zig
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub const SplitBundlerOptions = struct {
_ = val;
},
.rejected => |err| {
return global.throwValue2(err);
return global.throwValue(err);
},
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/bake/production.zig
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMa
params_buf.append(ctx.allocator, route.part.param) catch unreachable;
},
.catch_all, .catch_all_optional => {
global.throw("catch-all routes are not supported in static site generation", .{});
return global.throw("catch-all routes are not supported in static site generation", .{});
},
else => {},
}
Expand All @@ -439,7 +439,7 @@ pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMa
params_buf.append(ctx.allocator, parent.part.param) catch unreachable;
},
.catch_all, .catch_all_optional => {
global.throw("catch-all routes are not supported in static site generation", .{});
return global.throw("catch-all routes are not supported in static site generation", .{});
},
else => {},
}
Expand Down Expand Up @@ -532,8 +532,7 @@ pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMa
Output.flush();
},
.rejected => |err| {
vm.global.throwValue(err);
return error.JSError;
return vm.global.throwValue(err);
},
}
}
Expand All @@ -550,8 +549,7 @@ fn loadModule(vm: *VirtualMachine, global: *JSC.JSGlobalObject, key: JSValue) !J
return BakeGetModuleNamespace(global, key);
},
.rejected => |err| {
vm.global.throwValue(err);
return error.JSError;
return vm.global.throwValue(err);
},
}
}
Expand Down Expand Up @@ -616,11 +614,10 @@ export fn BakeProdResolve(global: *JSC.JSGlobalObject, a_str: bun.String, specif
defer referrer.deinit();

if (bun.resolver.isPackagePath(specifier.slice())) {
global.throw("Non-relative import {} from {} are not allowed in production assets. This is a bug in Bun's bundler", .{
return global.throw("Non-relative import {} from {} are not allowed in production assets. This is a bug in Bun's bundler", .{
bun.fmt.quote(specifier.slice()),
bun.fmt.quote(referrer.slice()),
});
return bun.String.dead;
}) catch bun.String.dead;
}

if (Environment.allow_assert)
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/BuildMessage.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub const BuildMessage = struct {
pub usingnamespace JSC.Codegen.JSBuildMessage;

pub fn constructor(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!*BuildMessage {
return globalThis.throw2("BuildMessage is not constructable", .{});
return globalThis.throw("BuildMessage is not constructable", .{});
}

pub fn getNotes(this: *BuildMessage, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/ResolveMessage.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const ResolveMessage = struct {
pub usingnamespace JSC.Codegen.JSResolveMessage;

pub fn constructor(globalThis: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!*ResolveMessage {
return globalThis.throw2("ResolveMessage is not constructable", .{});
return globalThis.throw("ResolveMessage is not constructable", .{});
}

pub fn getCode(this: *ResolveMessage, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
Expand Down
Loading
Loading