fix: handle broken symlinks in filewatcher initial scan#2156
Open
abhu85 wants to merge 1 commit intoaws:masterfrom
Open
fix: handle broken symlinks in filewatcher initial scan#2156abhu85 wants to merge 1 commit intoaws:masterfrom
abhu85 wants to merge 1 commit intoaws:masterfrom
Conversation
Add exception handling to _seed_mtime_cache to handle FileNotFoundError and other OS errors that can occur when scanning directories containing broken symlinks (e.g., Emacs lock files like .#app.py). Previously, the filewatcher would crash during initial cache seeding when encountering a symlink pointing to a non-existent file. This made the file watcher unusable, preventing hot-reloading during development. The fix catches (OSError, IOError) in _seed_mtime_cache, consistent with the existing error handling in _is_changed_file, and logs a debug message for skipped files. Fixes aws#997 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: abhu85 <user@users.noreply.github.com>
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
This PR fixes the file watcher crash when encountering broken symlinks during the initial cache seeding phase.
Problem: When a directory contains a symlink pointing to a non-existent file (such as Emacs lock files like
.#app.py), the_seed_mtime_cachemethod would crash with aFileNotFoundError, making the file watcher unusable and preventing hot-reloading during development.Solution: Add exception handling to
_seed_mtime_cacheto catch(OSError, IOError)when callingmtime(), consistent with the existing error handling in_is_changed_file. Files that cannot be stat'd are skipped with a debug log message.Changes
chalice/cli/filewatch/stat.py: Added try/except block in_seed_mtime_cacheto handle broken symlinkstests/unit/cli/filewatch/test_stat.py: Added regression testtest_can_handle_broken_symlink_during_initial_scanReproduction
Test Plan
pytest tests/unit/cli/filewatch/test_stat.py)Fixes #997
Generated with assistance from Claude Code