pass error all the way up to Layer chain to clean

This commit is contained in:
Muki Kiboigo
2026-04-27 07:20:06 -07:00
parent 4de1dc5424
commit 3fe774fbfb
4 changed files with 9 additions and 17 deletions

View File

@@ -402,10 +402,13 @@ pub fn request(self: *Client, req: Request) !void {
our_req.params.request_id = self.incrReqId();
const arena = try self.network.app.arena_pool.acquire(.small, "Request.arena");
errdefer self.network.app.arena_pool.release(arena);
our_req.params.arena = arena;
return self.entry_layer.request(self, our_req);
return self.entry_layer.request(self, our_req) catch |err| {
our_req.error_callback(our_req.ctx, err);
self.deinitRequest(our_req);
return err;
};
}
const SyncContext = struct {

View File

@@ -63,7 +63,6 @@ fn request(ptr: *anyopaque, client: *Client, req: Request) anyerror!void {
.timestamp = std.time.timestamp(),
.request_headers = req_header_list.items,
})) |cached| {
defer client.deinitRequest(req);
return serveFromCache(req, &cached);
}
@@ -104,8 +103,7 @@ fn serveFromCache(req: Request, cached: *const CachedResponse) !void {
const proceed = try req.header_callback(response);
if (!proceed) {
req.error_callback(req.ctx, error.Abort);
return;
return error.Abort;
}
switch (cached.data) {

View File

@@ -90,11 +90,7 @@ fn request(ptr: *anyopaque, client: *Client, in_req: Request) anyerror!void {
});
if (!wait_for_interception) {
return self.next.request(client, req) catch |err| {
req.error_callback(req.ctx, err);
client.deinitRequest(req);
return err;
};
return self.next.request(client, req);
}
self.intercepted += 1;
@@ -214,8 +210,8 @@ pub fn abortRequest(self: *InterceptionLayer, client: *Client, req: Request) voi
}
self.intercepted -= 1;
defer client.deinitRequest(req);
req.error_callback(req.ctx, error.Abort);
client.deinitRequest(req);
}
fn fulfillInner(

View File

@@ -63,11 +63,8 @@ fn request(ptr: *anyopaque, client: *Client, req: Request) anyerror!void {
const path = URL.getPathname(req.params.url);
if (!robots.isAllowed(path)) {
defer client.deinitRequest(req);
log.warn(.http, "blocked by robots", .{ .url = req.params.url });
req.error_callback(req.ctx, error.RobotsBlocked);
return;
return error.RobotsBlocked;
}
},
.absent => {},
@@ -85,8 +82,6 @@ fn fetchRobotsThenRequest(
robots_url: [:0]const u8,
req: Request,
) !void {
errdefer client.network.app.arena_pool.release(arena);
const entry = try self.pending.getOrPut(self.allocator, robots_url);
if (!entry.found_existing) {