Skip to content

Commit

Permalink
loop: log timeout and cancel errors instead of panicking
Browse files Browse the repository at this point in the history
  • Loading branch information
krichprollsch committed May 22, 2024
1 parent c3c6441 commit 0629bc6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub const IO = @import("tigerbeetle-io").IO;
const public = @import("api.zig");
const JSCallback = public.Callback;

const log = std.log.scoped(.loop);

fn report(comptime fmt: []const u8, args: anytype) void {
const max_len = 200;
var buf: [max_len]u8 = undefined;
Expand Down Expand Up @@ -109,7 +111,13 @@ pub const SingleThreaded = struct {
defer ctx.loop.freeCbk(completion, ctx);

// TODO: return the error to the callback
result catch |err| @panic(@errorName(err));
result catch |err| {
switch (err) {
error.Canceled => {},
else => log.err("timeout callback: {any}", .{err}),
}
return;
};

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

// TODO: return the error to the callback
result catch |err| @panic(@errorName(err));
result catch |err| {
log.err("cancel callback: {any}", .{err});
return;
};

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

const completion = self.alloc.create(IO.Completion) catch unreachable;
completion.* = undefined;
const ctx = self.alloc.create(ContextTimeout) catch unreachable;
const ctx = self.alloc.create(ContextCancel) catch unreachable;
ctx.* = ContextCancel{
.loop = self,
.js_cbk = js_cbk,
Expand Down

0 comments on commit 0629bc6

Please sign in to comment.