Skip to content

Commit dae7b07

Browse files
authored
Merge pull request #161 from gHashTag/feat/issue-160
fix(ws): replace catch unreachable with proper error handling
2 parents 4688968 + 1a4b3aa commit dae7b07

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)