fix(watcher): don't panic when a subdirectory can't be watched#3006
Open
arimu1 wants to merge 1 commit into
Open
fix(watcher): don't panic when a subdirectory can't be watched#3006arimu1 wants to merge 1 commit into
arimu1 wants to merge 1 commit into
Conversation
gitui --watcher panics with "unexpected panic" whenever the recursive
notify watch fails, e.g. when a subdirectory of the repo is owned by
another user (root-owned, or created by a container) and returns
PermissionDenied. The watcher thread's .expect("Watch error") turns
that into a hard panic that tears down the terminal and closes gitui.
Handle the watch() error gracefully instead: log it and skip live
file watching for that thread, so a repo with a foreign-owned
subdirectory still opens normally. gitui simply runs without
live-refresh in that case, same as with --updater ticker.
Fixes gitui-org#2900
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.
Bug
gitui --watcherpanics with "GitUI was closed due to an unexpected panic" whenever the recursivenotifywatch fails to add a watch for some subdirectory of the repo, e.g. when that subdirectory is owned by a different user (root-owned, or created via a container/podman) and the OS returnsPermissionDenied.The panic happens on a background thread (spawned in
RepoWatcher::new), but the process-wide panic hook tears down the terminal as soon as it fires, so the user just sees gitui close.Repro (from #2900):
Fix
Replace the fatal
.expect("Watch error")increate_watcher(src/watcher.rs) with amatchon thewatch()result: on success the debouncer is kept alive as before, on failure the error is logged and the function returns without panicking. gitui starts up normally and keeps working, just without live file-watching for that session (comparable to running with--updater ticker).Testing
watcher::tests::test_create_watcher_does_not_panic_on_watch_error, which callscreate_watcherwith a path that can't be watched and asserts it doesn't panic. This exercises the exact code path from the issue without needing root/container setup to reproduce thePermissionDeniedspecifically.cargo fmt -- --check— cleancargo clippy --workspace --all-features— cleancargo test --bin gitui— 80 passed, 0 failed (includes the new test)cargo test --workspace— 175/177 pass; the 2 failures (sync::sign::tests::test_openpgp_sign_and_verify_e2e,sync::sign::tests::test_x509_sign_and_verify_e2e) are pre-existing onupstream/masterunmodified, caused bygpg/gpgsmnot being installed on my machine, unrelated to this change.Added a CHANGELOG entry under
Unreleased.Fixes #2900