Skip to content

Commit 8f5d990

Browse files
authored
refactor: replace error propagation with direct exit codes (#24)
1 parent 9bf6914 commit 8f5d990

File tree

4 files changed

+4
-13
lines changed

4 files changed

+4
-13
lines changed

src/bun.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub fn main() !void {
66
defer _ = gpa.deinit();
77

88
const allocator = gpa.allocator();
9-
utils.run_main(allocator, utils.Cmd.bun);
9+
try utils.run(allocator, utils.Cmd.bun);
1010
}

src/bunx.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub fn main() !void {
66
defer _ = gpa.deinit();
77

88
const allocator = gpa.allocator();
9-
utils.run_main(allocator, utils.Cmd.bunx);
9+
try utils.run(allocator, utils.Cmd.bunx);
1010
}

src/utils.zig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ pub const Cmd = enum {
1111
bunx,
1212
};
1313

14-
/// Wrapper for run that handles common errors like UserAborted
15-
pub fn run_main(allocator: mem.Allocator, cmd: Cmd) void {
16-
run(allocator, cmd) catch |err| {
17-
// Just exit gracefully for UserAborted since we already displayed an error message
18-
if (err == error.UserAborted) std.process.exit(1);
19-
std.debug.print("Error: {s}\n", .{@errorName(err)});
20-
std.process.exit(1);
21-
};
22-
}
23-
2414
pub fn run(allocator: mem.Allocator, cmd: Cmd) !void {
2515
const is_debug = try isDebug(allocator);
2616
if (is_debug) std.debug.print("Executable: {}\n", .{cmd});

src/vm.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ fn confirmInstallation(version: []const u8) !void {
249249
try stdout.print("{s}Bun v{s} is not installed. Run in an interactive terminal to install or set BUNV_AUTO_INSTALL=1.{s}\n", .{ c.yellow, version, c.reset });
250250
}
251251

252-
return error.UserAborted;
252+
std.debug.print("Installation aborted by user\n", .{});
253+
std.process.exit(1);
253254
}
254255

255256
pub fn getVersionsDir(allocator: mem.Allocator, config_dir: []const u8) ![]u8 {

0 commit comments

Comments
 (0)