From ec92b61663085c98be07d816a749dd6f50e5e131 Mon Sep 17 00:00:00 2001 From: David Kaya Date: Mon, 13 Apr 2026 09:24:24 +0200 Subject: [PATCH] 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> --- src/main/services/projectCustomizationWatcher.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/services/projectCustomizationWatcher.ts b/src/main/services/projectCustomizationWatcher.ts index afc2bd3..72b79e1 100644 --- a/src/main/services/projectCustomizationWatcher.ts +++ b/src/main/services/projectCustomizationWatcher.ts @@ -169,7 +169,14 @@ async function collectExistingDirectories(rootPath: string): Promise { } 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; }