fix: handle async FSWatcher errors in project customization watcher

On Linux, fs.watch() on a non-existent directory emits an asynchronous
'error' event instead of throwing synchronously. Without an error handler,
this crashes the process. Tests that create AryxAppService with fake
project paths (e.g. C:\workspace\project-one) trigger this on Linux CI
because those paths don't exist.

Attach an 'error' event handler to the FSWatcher that logs a warning and
closes the watcher gracefully. This fixes the Linux CI 'bun test' failure
and also prevents production crashes if a watched directory is deleted
at runtime.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David Kaya
2026-04-13 09:24:24 +02:00
co-authored by Copilot
parent 524380e2b5
commit ec92b61663
@@ -169,7 +169,14 @@ async function collectExistingDirectories(rootPath: string): Promise<string[]> {
}
function createProjectWatchHandle(directoryPath: string, onChange: () => void): ProjectWatchHandle {
return watch(directoryPath, { persistent: false }, () => {
const watcher = watch(directoryPath, { persistent: false }, () => {
onChange();
});
watcher.on('error', (error) => {
console.warn(`[aryx customization] Watcher error for ${directoryPath}:`, error);
watcher.close();
});
return watcher;
}