From 933752ad46b2b5bd5b41d113c97b84310c642a86 Mon Sep 17 00:00:00 2001 From: Erick Z <567737+eckz@users.noreply.github.com> Date: Tue, 25 Mar 2025 05:16:33 +0100 Subject: [PATCH] Don't panic on temporary files in file watcher (#18462) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective Fixes #18461 Apparently `RustRover` creates a temporary file with a tilde like `load_scene_example.scn.ron~` and at the moment of calling `.canonicalize()` the file does not exists anymore. ## Solution Not call `.unwrap()` and return `None` fixes the issue. ## Testing - `cargo ci`: OK - Tested the `scene` example with `file_watcher` feature and it works as expected. Co-authored-by: François Mockers --- crates/bevy_asset/src/io/file/file_watcher.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_asset/src/io/file/file_watcher.rs b/crates/bevy_asset/src/io/file/file_watcher.rs index f1a26853c4..e70cf1665f 100644 --- a/crates/bevy_asset/src/io/file/file_watcher.rs +++ b/crates/bevy_asset/src/io/file/file_watcher.rs @@ -35,7 +35,7 @@ impl FileWatcher { sender: Sender, debounce_wait_time: Duration, ) -> Result { - let root = normalize_path(&path).canonicalize().unwrap(); + let root = normalize_path(&path).canonicalize()?; let watcher = new_asset_event_debouncer( path.clone(), debounce_wait_time, @@ -262,7 +262,7 @@ impl FilesystemEventHandler for FileEventHandler { self.last_event = None; } fn get_path(&self, absolute_path: &Path) -> Option<(PathBuf, bool)> { - let absolute_path = absolute_path.canonicalize().unwrap(); + let absolute_path = absolute_path.canonicalize().ok()?; Some(get_asset_path(&self.root, &absolute_path)) }