fix: log before stopping watch thread on handler error

This commit is contained in:
CJ van den Berg 2026-03-14 23:51:11 +01:00
parent 1574e4b446
commit 2e1f469e3e
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 36 additions and 9 deletions

View file

@ -136,7 +136,10 @@ fn thread_fn(self: *@This(), allocator: std.mem.Allocator) void {
if (file_path_len > 0) {
const fp = file_path_buf[0..file_path_len];
if (ev.fflags & (NOTE_WRITE | NOTE_EXTEND) != 0)
self.handler.change(fp, EventType.modified, .file) catch return;
self.handler.change(fp, EventType.modified, .file) catch |e| {
std.log.err("nightwatch: handler returned {s}, stopping watch thread", .{@errorName(e)});
return;
};
continue;
}
@ -157,9 +160,15 @@ fn thread_fn(self: *@This(), allocator: std.mem.Allocator) void {
if (dir_path_len == 0) continue;
const dir_path = dir_path_buf[0..dir_path_len];
if (ev.fflags & NOTE_DELETE != 0) {
self.handler.change(dir_path, EventType.deleted, .dir) catch return;
self.handler.change(dir_path, EventType.deleted, .dir) catch |e| {
std.log.err("nightwatch: handler returned {s}, stopping watch thread", .{@errorName(e)});
return;
};
} else if (ev.fflags & NOTE_RENAME != 0) {
self.handler.change(dir_path, EventType.renamed, .dir) catch return;
self.handler.change(dir_path, EventType.renamed, .dir) catch |e| {
std.log.err("nightwatch: handler returned {s}, stopping watch thread", .{@errorName(e)});
return;
};
} else if (ev.fflags & NOTE_WRITE != 0) {
self.scan_dir(allocator, dir_path) catch {};
}