Skip to content

Commit 0629bc6

Browse files
committed
loop: log timeout and cancel errors instead of panicking
1 parent c3c6441 commit 0629bc6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/loop.zig

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub const IO = @import("tigerbeetle-io").IO;
2020
const public = @import("api.zig");
2121
const JSCallback = public.Callback;
2222

23+
const log = std.log.scoped(.loop);
24+
2325
fn report(comptime fmt: []const u8, args: anytype) void {
2426
const max_len = 200;
2527
var buf: [max_len]u8 = undefined;
@@ -109,7 +111,13 @@ pub const SingleThreaded = struct {
109111
defer ctx.loop.freeCbk(completion, ctx);
110112

111113
// TODO: return the error to the callback
112-
result catch |err| @panic(@errorName(err));
114+
result catch |err| {
115+
switch (err) {
116+
error.Canceled => {},
117+
else => log.err("timeout callback: {any}", .{err}),
118+
}
119+
return;
120+
};
113121

114122
const old_events_nb = ctx.loop.removeEvent();
115123
if (builtin.is_test) {
@@ -155,7 +163,10 @@ pub const SingleThreaded = struct {
155163
defer ctx.loop.freeCbk(completion, ctx);
156164

157165
// TODO: return the error to the callback
158-
result catch |err| @panic(@errorName(err));
166+
result catch |err| {
167+
log.err("cancel callback: {any}", .{err});
168+
return;
169+
};
159170

160171
const old_events_nb = ctx.loop.removeEvent();
161172
if (builtin.is_test) {
@@ -176,7 +187,7 @@ pub const SingleThreaded = struct {
176187

177188
const completion = self.alloc.create(IO.Completion) catch unreachable;
178189
completion.* = undefined;
179-
const ctx = self.alloc.create(ContextTimeout) catch unreachable;
190+
const ctx = self.alloc.create(ContextCancel) catch unreachable;
180191
ctx.* = ContextCancel{
181192
.loop = self,
182193
.js_cbk = js_cbk,

0 commit comments

Comments
 (0)