From a2c8a583a6adf9a0a936c151f2ab361d647b4400 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 6 Feb 2026 19:51:46 -0600 Subject: [PATCH] Refactor StdBackend error handling for file watcher reliability - Updated the `new` method in `StdBackend` to improve error handling for file watching. - Introduced specific handling for `WatcherCriticalError::RescanRequired`, allowing the watcher to recover from rapid changes while logging a warning. - Ensured that all other critical errors will terminate the process, maintaining reliability in file watching operations. --- crates/memofs/src/std_backend.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/memofs/src/std_backend.rs b/crates/memofs/src/std_backend.rs index 96cfb590..ac97383d 100644 --- a/crates/memofs/src/std_backend.rs +++ b/crates/memofs/src/std_backend.rs @@ -64,11 +64,29 @@ pub struct StdBackend { } impl StdBackend { - /// Creates a new StdBackend with default error handling (logs and exits on critical errors). + /// Creates a new StdBackend with default error handling. + /// + /// `RescanRequired` is treated as recoverable (the debouncer will re-walk + /// the directory tree). All other critical errors terminate the process + /// because file watching cannot continue. pub fn new() -> StdBackend { Self::new_with_error_handler(Box::new(|err| { - log::error!("{}. File watching is no longer reliable.", err); - std::process::exit(1); + match &err { + WatcherCriticalError::RescanRequired => { + // Recoverable: the debouncer lost some events due to rapid + // changes and will rescan the watched directories. Log a + // warning but keep the watcher thread alive. + log::warn!( + "File watcher requested rescan due to rapid changes. \ + Some file events may have been missed." + ); + false // keep watcher running + } + _ => { + log::error!("{}. File watching is no longer reliable.", err); + std::process::exit(1); + } + } })) }