Skip to content

Commit 4688968

Browse files
authored
Merge pull request #158 from gHashTag/feat/issue-156
fix(serve): replace catch unreachable with try in tri_serve.zig init
2 parents 3ab50ac + b0a166d commit 4688968

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

src/tri/tri_serve.zig

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,13 @@ pub const ServerStatus = struct {
8888
start_time: i64,
8989
allocator: std.mem.Allocator,
9090

91-
pub fn init(allocator: std.mem.Allocator) ServerStatus {
92-
const protocols = std.ArrayList([]const u8).initCapacity(allocator, 4) catch return ServerStatus{
93-
.running = false,
94-
.uptime = 0,
95-
.connections = 0,
96-
.protocols_active = std.ArrayList([]const u8).initCapacity(allocator, 0) catch unreachable,
97-
.start_time = 0,
98-
.allocator = allocator,
99-
};
91+
pub fn init(allocator: std.mem.Allocator) !ServerStatus {
92+
const protocols = std.ArrayList([]const u8).initCapacity(allocator, 4);
10093
return ServerStatus{
10194
.running = false,
10295
.uptime = 0,
10396
.connections = 0,
104-
.protocols_active = protocols,
97+
.protocols_active = try protocols,
10598
.start_time = 0,
10699
.allocator = allocator,
107100
};
@@ -127,7 +120,7 @@ pub const UnifiedApiServer = struct {
127120
const server = UnifiedApiServer{
128121
.allocator = allocator,
129122
.config = config,
130-
.status = ServerStatus.init(allocator),
123+
.status = try ServerStatus.init(allocator),
131124
.registry = api.CommandRegistry.init(allocator),
132125
.server_socket = null,
133126
};
@@ -1056,7 +1049,7 @@ test "ServeConfig defaults" {
10561049
}
10571050

10581051
test "ServerStatus init" {
1059-
var status = ServerStatus.init(std.testing.allocator);
1052+
var status = try ServerStatus.init(std.testing.allocator);
10601053
defer status.deinit();
10611054

10621055
try std.testing.expect(!status.running);

0 commit comments

Comments
 (0)