fix: log before stopping watch thread on handler error
This commit is contained in:
parent
1574e4b446
commit
2e1f469e3e
3 changed files with 36 additions and 9 deletions
|
|
@ -121,7 +121,10 @@ pub fn Create(comptime variant: InterfaceType) type {
|
||||||
_ = std.posix.poll(&pfds, -1) catch return;
|
_ = std.posix.poll(&pfds, -1) catch return;
|
||||||
if (pfds[1].revents & std.posix.POLL.IN != 0) return; // stop signal
|
if (pfds[1].revents & std.posix.POLL.IN != 0) return; // stop signal
|
||||||
if (pfds[0].revents & std.posix.POLL.IN != 0) {
|
if (pfds[0].revents & std.posix.POLL.IN != 0) {
|
||||||
self.handle_read_ready(allocator) catch return;
|
self.handle_read_ready(allocator) catch |e| {
|
||||||
|
std.log.err("nightwatch: handler returned {s}, stopping watch thread", .{@errorName(e)});
|
||||||
|
return;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,10 @@ fn thread_fn(self: *@This(), allocator: std.mem.Allocator) void {
|
||||||
if (file_path_len > 0) {
|
if (file_path_len > 0) {
|
||||||
const fp = file_path_buf[0..file_path_len];
|
const fp = file_path_buf[0..file_path_len];
|
||||||
if (ev.fflags & (NOTE_WRITE | NOTE_EXTEND) != 0)
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,9 +160,15 @@ fn thread_fn(self: *@This(), allocator: std.mem.Allocator) void {
|
||||||
if (dir_path_len == 0) continue;
|
if (dir_path_len == 0) continue;
|
||||||
const dir_path = dir_path_buf[0..dir_path_len];
|
const dir_path = dir_path_buf[0..dir_path_len];
|
||||||
if (ev.fflags & NOTE_DELETE != 0) {
|
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) {
|
} 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) {
|
} else if (ev.fflags & NOTE_WRITE != 0) {
|
||||||
self.scan_dir(allocator, dir_path) catch {};
|
self.scan_dir(allocator, dir_path) catch {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,17 +124,32 @@ fn thread_fn(self: *@This(), allocator: std.mem.Allocator) void {
|
||||||
if (is_file) {
|
if (is_file) {
|
||||||
// Explicit file watch: emit events with .file type directly.
|
// Explicit file watch: emit events with .file type directly.
|
||||||
if (ev.fflags & NOTE_DELETE != 0) {
|
if (ev.fflags & NOTE_DELETE != 0) {
|
||||||
self.handler.change(watch_path, EventType.deleted, .file) catch return;
|
self.handler.change(watch_path, EventType.deleted, .file) catch |e| {
|
||||||
|
std.log.err("nightwatch: handler returned {s}, stopping watch thread", .{@errorName(e)});
|
||||||
|
return;
|
||||||
|
};
|
||||||
} else if (ev.fflags & NOTE_RENAME != 0) {
|
} else if (ev.fflags & NOTE_RENAME != 0) {
|
||||||
self.handler.change(watch_path, EventType.renamed, .file) catch return;
|
self.handler.change(watch_path, EventType.renamed, .file) catch |e| {
|
||||||
|
std.log.err("nightwatch: handler returned {s}, stopping watch thread", .{@errorName(e)});
|
||||||
|
return;
|
||||||
|
};
|
||||||
} else if (ev.fflags & (NOTE_WRITE | NOTE_EXTEND) != 0) {
|
} else if (ev.fflags & (NOTE_WRITE | NOTE_EXTEND) != 0) {
|
||||||
self.handler.change(watch_path, EventType.modified, .file) catch return;
|
self.handler.change(watch_path, EventType.modified, .file) catch |e| {
|
||||||
|
std.log.err("nightwatch: handler returned {s}, stopping watch thread", .{@errorName(e)});
|
||||||
|
return;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ev.fflags & NOTE_DELETE != 0) {
|
if (ev.fflags & NOTE_DELETE != 0) {
|
||||||
self.handler.change(watch_path, EventType.deleted, .dir) catch return;
|
self.handler.change(watch_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) {
|
} else if (ev.fflags & NOTE_RENAME != 0) {
|
||||||
self.handler.change(watch_path, EventType.renamed, .dir) catch return;
|
self.handler.change(watch_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) {
|
} else if (ev.fflags & NOTE_WRITE != 0) {
|
||||||
self.scan_dir(allocator, watch_path) catch {};
|
self.scan_dir(allocator, watch_path) catch {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue