Skip to content

Commit ee59748

Browse files
Trinity Agentclaude
andcommitted
fix(ws): replace catch unreachable with proper error handling (#160)
- Changed WSClient.init signature to return !WSClient - Used try for stream.address error propagation - Updated listenerLoop to handle errors with logging and cleanup Closes #160 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 907b37b commit ee59748

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/tri/websocket/intelligence_server.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ pub const WSClient = struct {
204204

205205
mutex: std.Thread.Mutex,
206206

207-
pub fn init(allocator: Allocator, stream: net.Stream) WSClient {
207+
pub fn init(allocator: Allocator, stream: net.Stream) !WSClient {
208208
return .{
209209
.allocator = allocator,
210210
.stream = stream,
211-
.address = stream.address catch unreachable,
211+
.address = try stream.address,
212212
.connected = true,
213213
.mutex = std.Thread.Mutex{},
214214
};
@@ -370,7 +370,12 @@ pub const WSServer = struct {
370370
stream.close();
371371
continue;
372372
};
373-
client_ptr.* = WSClient.init(server.allocator, stream);
373+
client_ptr.* = WSClient.init(server.allocator, stream) catch |err| {
374+
stdout.print("Failed to get client address: {}\n", .{err}) catch {};
375+
server.allocator.destroy(client_ptr);
376+
stream.close();
377+
continue;
378+
};
374379

375380
server.mutex.lock();
376381
server.clients.append(server.allocator, client_ptr) catch {

0 commit comments

Comments
 (0)