fix: propagate unwatch() errors if backend.remove_watch can fail

This commit is contained in:
CJ van den Berg 2026-03-14 18:13:26 +01:00
parent f107b97214
commit 505b9efeb8
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 10 additions and 3 deletions

View file

@ -175,11 +175,18 @@ pub fn Create(comptime variant: Variant) type {
}
}
const UnwatchReturnType = @typeInfo(@TypeOf(Backend.remove_watch)).@"fn".return_type orelse void;
pub const UnwatchError = switch (@typeInfo(UnwatchReturnType)) {
.error_union => |info| info.error_set,
.void => error{},
else => @compileError("invalid remove_watch return type: " ++ @typeName(UnwatchReturnType)),
};
/// Stop watching a previously watched path. Has no effect if `path`
/// was never watched. Does not unwatch subdirectories that were
/// added automatically as a result of watching `path`.
pub fn unwatch(self: *@This(), path: []const u8) void {
self.interceptor.backend.remove_watch(self.allocator, path);
pub fn unwatch(self: *@This(), path: []const u8) UnwatchError!void {
return self.interceptor.backend.remove_watch(self.allocator, path);
}
/// Read pending events from the backend fd and deliver them to the handler.

View file

@ -395,7 +395,7 @@ fn testUnwatch(comptime Watcher: type, allocator: std.mem.Allocator) !void {
try drainEvents(Watcher, &watcher);
try std.testing.expect(th.hasChange(file1, .created, .file));
watcher.unwatch(tmp);
watcher.unwatch(tmp) catch return error.TestUnexpectedResult;
const count_before = th.events.items.len;
const file2 = try std.fs.path.join(allocator, &.{ tmp, "after_unwatch.txt" });