From 1a4b3aa7a25d9ad547c638dec5922ca0733da177 Mon Sep 17 00:00:00 2001 From: Trinity Agent Date: Wed, 11 Mar 2026 18:22:58 +0000 Subject: [PATCH] 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 --- src/tri/websocket/intelligence_server.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tri/websocket/intelligence_server.zig b/src/tri/websocket/intelligence_server.zig index 7c0a2c4bca..ddfc9b7de3 100644 --- a/src/tri/websocket/intelligence_server.zig +++ b/src/tri/websocket/intelligence_server.zig @@ -204,11 +204,11 @@ pub const WSClient = struct { mutex: std.Thread.Mutex, - pub fn init(allocator: Allocator, stream: net.Stream) WSClient { + pub fn init(allocator: Allocator, stream: net.Stream) !WSClient { return .{ .allocator = allocator, .stream = stream, - .address = stream.address catch unreachable, + .address = try stream.address, .connected = true, .mutex = std.Thread.Mutex{}, }; @@ -370,7 +370,12 @@ pub const WSServer = struct { stream.close(); continue; }; - client_ptr.* = WSClient.init(server.allocator, stream); + client_ptr.* = WSClient.init(server.allocator, stream) catch |err| { + stdout.print("Failed to get client address: {}\n", .{err}) catch {}; + server.allocator.destroy(client_ptr); + stream.close(); + continue; + }; server.mutex.lock(); server.clients.append(server.allocator, client_ptr) catch {