fix: drop missing files from state when content fetch hits ENOENT#196
Merged
fix: drop missing files from state when content fetch hits ENOENT#196
Conversation
When a file is deleted from disk while the server is running, the watcher sometimes misses the event (e.g. fsnotify on macOS) and the entry lingers in the sidebar showing "Failed to load file." Detect ENOENT during the content fetch and remove every reference to that path across all groups. Empty groups without patterns are dropped.
This comment has been minimized.
This comment has been minimized.
The slice is reused with g.Files[:0], so without zeroing the truncated tail the removed entries stay reachable through the backing array until the slice grows again. Nil out the tail explicitly.
Contributor
Code Metrics Report
Details | | main (c9b5218) | #196 (39e45cd) | +/- |
|---------------------|----------------|----------------|-------|
+ | Coverage | 57.7% | 58.0% | +0.3% |
| Files | 44 | 44 | 0 |
| Lines | 3724 | 3761 | +37 |
+ | Covered | 2149 | 2184 | +35 |
- | Code to Test Ratio | 1:0.5 | 1:0.5 | -0.1 |
| Code | 5959 | 5999 | +40 |
| Test | 3077 | 3077 | 0 |
| Test Execution Time | 35s | 35s | 0s |Code coverage of files in pull request scope (78.6% → 79.0%)
Reported by octocov |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves server-side state hygiene when a markdown file disappears from disk while the server is running (notably when fsnotify misses a remove event on macOS), ensuring the UI doesn’t retain a “Failed to load file.” entry indefinitely.
Changes:
- Add
State.RemoveFilesByPathto remove all entries referencing a given path across all groups, clean up watches, and drop now-empty groups without patterns. - Update
handleFileContentto treatos.IsNotExistfromos.ReadFileas a signal to remove the file from state and return404. - Add tests covering removal-on-content-fetch and cross-group cleanup behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/server/server.go | Adds removal-by-path state cleanup and integrates it into the file content API when reads hit ENOENT. |
| internal/server/server_test.go | Adds tests ensuring missing-file content fetches remove stale entries and empty groups are cleaned up. |
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.
Summary
os.ReadFileinhandleFileContentfails withos.IsNotExist, call the newRemoveFilesByPathto drop every entry referencing that path from all groups; groups left empty without patterns are deleted.updateSSE event is emitted so the frontend re-syncs immediately.