From c11ed02760958c0a4509d15b500cfaf5f1ddea28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Mon, 27 Oct 2025 13:11:30 +0800 Subject: [PATCH] fix: fallback to `PollWatcher` instead of panicking when `RecommendedWatcher` initialization fails (#3281) --- yazi-watcher/src/local/local.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/yazi-watcher/src/local/local.rs b/yazi-watcher/src/local/local.rs index 2525e59c..2f1de80a 100644 --- a/yazi-watcher/src/local/local.rs +++ b/yazi-watcher/src/local/local.rs @@ -5,6 +5,7 @@ use hashbrown::HashSet; use notify::{PollWatcher, RecommendedWatcher, RecursiveMode, Watcher}; use tokio::{pin, sync::mpsc::{self, UnboundedReceiver}}; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; +use tracing::error; use yazi_fs::{File, FilesOp, provider}; use yazi_shared::url::{UrlBuf, UrlLike}; use yazi_vfs::VfsFile; @@ -26,10 +27,16 @@ impl Local { } }; - Self(if yazi_adapter::WSL.get() || cfg!(target_os = "netbsd") { - Box::new(PollWatcher::new(handler, config).unwrap()) - } else { - Box::new(RecommendedWatcher::new(handler, config).unwrap()) + if cfg!(target_os = "netbsd") || yazi_adapter::WSL.get() { + return Self(Box::new(PollWatcher::new(handler, config).unwrap())); + } + + Self(match RecommendedWatcher::new(handler.clone(), config) { + Ok(watcher) => Box::new(watcher), + Err(e) => { + error!("Falling back to PollWatcher due to RecommendedWatcher init failure: {e:?}"); + Box::new(PollWatcher::new(handler, config).unwrap()) + } }) }