Skip to content

fix(desktop): don't crash on unwatchable image directories (UNC/WSL paths) - #4853

Merged
Jocs merged 1 commit into
developfrom
fix/3779-image-watch-guard
Jul 5, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/3779-image-watch-guard

Conversation

@Jocs

@Jocs Jocs commented Jul 4, 2026

Copy link
Copy Markdown
Member

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:

Unexpected error: EISDIR: illegal operation on a directory, watch '\\wsl.localhost\Ubuntu\...\md-images'

Root cause: the image-path auto-complete helper (packages/desktop/src/main/utils/imagePathAutoComplement.ts) starts an fs.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 the fs.readdir callback of searchFilesAndDir, the throw escapes as an uncaught exception caught only by the global uncaughtException handler, 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)" — stubs fs.watch to throw EISDIR and asserts searchFilesAndDir still resolves with the scanned entries and leaves the directory untracked. Verified RED on develop (the throw escaped as an uncaught exception / hung the promise) → GREEN with the fix. Existing tests in the spec stay green; typecheck and eslint pass.

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]>
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4853:

Run: https://github.com/marktext/marktext/actions/runs/28708130882

Artifact Size Link
marktext-windows-arm64 275.7 MB Download
marktext-macos-x64 293.1 MB Download
marktext-windows-x64 283.9 MB Download
marktext-linux 627.5 MB Download
marktext-macos-arm64 282.7 MB Download

@Jocs
Jocs merged commit 642a0ea into develop Jul 5, 2026
10 of 11 checks passed
@Jocs
Jocs deleted the fix/3779-image-watch-guard branch July 5, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected error: EISDIR: illegal operation on a directory, watch '\\wsl.localhost\Ubuntu\home\eric\Projects-client\subatomic\client-import\md-images'

1 participant