Repository navigation
fix(desktop): don't crash on unwatchable image directories (UNC/WSL paths) - #4853
Merged
Merged
Conversation
The image-path auto-complete helper calls fs.watch() on the directory of the path being typed, with no error handling. fs.watch throws synchronously for directories the OS can't watch — notably UNC / \\wsl.localhost network paths on Windows (EISDIR). The throw happened inside the fs.readdir callback of searchFilesAndDir, so it escaped as an uncaught exception and surfaced to the user as the generic "Unexpected error occurred in the main process" dialog. Wrap fs.watch in try/catch and attach an 'error' listener to the watcher so auto-complete silently degrades to "not watching" that directory instead of crashing the main process. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #3779.
Typing an image path (or loading a document that references one) whose directory lives on an unwatchable location — e.g. a
\\wsl.localhost\...UNC path on Windows — pops the generic "Unexpected error occurred in the main process" dialog:Root cause: the image-path auto-complete helper (
packages/desktop/src/main/utils/imagePathAutoComplement.ts) starts anfs.watch()on the scanned directory with no error handling.fs.watch()throws synchronously for directories the OS can't watch (UNC/network mounts, some WSL paths →EISDIR). Because the call runs inside thefs.readdircallback ofsearchFilesAndDir, the throw escapes as an uncaught exception caught only by the globaluncaughtExceptionhandler, whose message is exactly the reported dialog text.Fix
Wrap the
fs.watch()call in try/catch and attach an'error'listener to the returned watcher (for failures that surface after construction). When a directory can't be watched, auto-complete simply degrades to "not watching" it — the scan result is still returned — instead of crashing the main process.Tests
Added to
test/unit/specs/image-path-autocomplete.spec.ts: "still resolves when the directory cannot be watched (UNC/WSL paths, #3779)" — stubsfs.watchto throwEISDIRand assertssearchFilesAndDirstill resolves with the scanned entries and leaves the directory untracked. Verified RED ondevelop(the throw escaped as an uncaught exception / hung the promise) → GREEN with the fix. Existing tests in the spec stay green;typecheckandeslintpass.