Skip to content

fix(watcher): don't panic when a subdirectory can't be watched#3006

Open
arimu1 wants to merge 1 commit into
gitui-org:masterfrom
arimu1:fix/2900-watcher-permission-degrade
Open

fix(watcher): don't panic when a subdirectory can't be watched#3006
arimu1 wants to merge 1 commit into
gitui-org:masterfrom
arimu1:fix/2900-watcher-permission-degrade

Conversation

@arimu1

@arimu1 arimu1 commented Jul 23, 2026

Copy link
Copy Markdown

Bug

gitui --watcher panics with "GitUI was closed due to an unexpected panic" whenever the recursive notify watch 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 returns PermissionDenied.

panicked at src/watcher.rs:79:10:
Watch error: Error { kind: Io(Os { code: 13, kind: PermissionDenied, message: "Permission denied" }), paths: ["/home/user/gitui-test/mydir"] }

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):

mkdir projectX && cd projectX && git init
podman run --rm -v "$(pwd):/workdir" alpine:latest /bin/sh -c \
  'mkdir /workdir/test && chown 1000:1000 /workdir/test && chmod 700 /workdir/test'
RUST_BACKTRACE=1 RUST_LOG=debug gitui --watcher

Fix

Replace the fatal .expect("Watch error") in create_watcher (src/watcher.rs) with a match on the watch() 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

  • Added watcher::tests::test_create_watcher_does_not_panic_on_watch_error, which calls create_watcher with 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 the PermissionDenied specifically.
  • cargo fmt -- --check — clean
  • cargo clippy --workspace --all-features — clean
  • cargo 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 on upstream/master unmodified, caused by gpg/gpgsm not being installed on my machine, unrelated to this change.

Added a CHANGELOG entry under Unreleased.

Fixes #2900

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
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.

GitUI was close due to an unexpected panic (file: "src/watcher.rs")

1 participant