Skip to content

Commit 054e20c

Browse files
committed
loop: log timeout and cancel errors instead of panicking
1 parent 23587d5 commit 054e20c

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;
@@ -113,7 +115,13 @@ pub const SingleThreaded = struct {
113115
defer ctx.loop.freeCbk(completion, ctx);
114116

115117
// TODO: return the error to the callback
116-
result catch |err| @panic(@errorName(err));
118+
result catch |err| {
119+
switch (err) {
120+
error.Canceled => {},
121+
else => log.err("timeout callback: {any}", .{err}),
122+
}
123+
return;
124+
};
117125

118126
const old_events_nb = ctx.loop.removeEvent();
119127
if (builtin.is_test) {
@@ -159,7 +167,10 @@ pub const SingleThreaded = struct {
159167
defer ctx.loop.freeCbk(completion, ctx);
160168

161169
// TODO: return the error to the callback
162-
result catch |err| @panic(@errorName(err));
170+
result catch |err| {
171+
log.err("cancel callback: {any}", .{err});
172+
return;
173+
};
163174

164175
const old_events_nb = ctx.loop.removeEvent();
165176
if (builtin.is_test) {
@@ -180,7 +191,7 @@ pub const SingleThreaded = struct {
180191

181192
const completion = self.alloc.create(IO.Completion) catch unreachable;
182193
completion.* = undefined;
183-
const ctx = self.alloc.create(ContextTimeout) catch unreachable;
194+
const ctx = self.alloc.create(ContextCancel) catch unreachable;
184195
ctx.* = ContextCancel{
185196
.loop = self,
186197
.js_cbk = js_cbk,

0 commit comments

Comments
 (0)