Skip to content

Commit

Permalink
Provide more information when a filewatcher failure is hit. (#13715)
Browse files Browse the repository at this point in the history
A naked unwrap led to an opaque error that can be hit when using the
embedded filewatcher.

I've changed this an unwrap_or_else panic! with the error message
providing more details about the failed operation.

A better solution would be to print an error! and not panic...

This was tested with the asset_processing example.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
  • Loading branch information
brandon-reinhart and alice-i-cecile authored Jun 6, 2024
1 parent f7ae277 commit 3122c87
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/bevy_asset/src/io/file/file_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ impl FileWatcher {
impl AssetWatcher for FileWatcher {}

pub(crate) fn get_asset_path(root: &Path, absolute_path: &Path) -> (PathBuf, bool) {
let relative_path = absolute_path.strip_prefix(root).unwrap();
let relative_path = absolute_path.strip_prefix(root).unwrap_or_else(|_| {
panic!(
"FileWatcher::get_asset_path() failed to strip prefix from absolute path: absolute_path={:?}, root={:?}",
absolute_path,
root
)
});
let is_meta = relative_path
.extension()
.map(|e| e == "meta")
Expand Down

0 comments on commit 3122c87

Please sign in to comment.