fix(coding-agent,mom): retry fs watchers on async errors closes #3564

This commit is contained in:
Mario Zechner
2026-04-22 23:03:19 +02:00
parent cc76e73c05
commit f3a2c9d05e
9 changed files with 300 additions and 88 deletions

View File

@@ -0,0 +1,30 @@
import { type FSWatcher, type WatchListener, watch } from "node:fs";
export const FS_WATCH_RETRY_DELAY_MS = 5000;
export function closeWatcher(watcher: FSWatcher | null | undefined): void {
if (!watcher) {
return;
}
try {
watcher.close();
} catch {
// Ignore watcher close errors
}
}
export function watchWithErrorHandler(
path: string,
listener: WatchListener<string>,
onError: () => void,
): FSWatcher | null {
try {
const watcher = watch(path, listener);
watcher.on("error", onError);
return watcher;
} catch {
onError();
return null;
}
}