Provide more information when a filewatcher failure is hit. (#13715)

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>
This commit is contained in:
Brandon Reinhart 2024-06-06 14:20:07 -05:00 committed by GitHub
parent f7ae277025
commit 3122c87702
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -46,7 +46,13 @@ impl FileWatcher {
impl AssetWatcher for FileWatcher {} impl AssetWatcher for FileWatcher {}
pub(crate) fn get_asset_path(root: &Path, absolute_path: &Path) -> (PathBuf, bool) { 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 let is_meta = relative_path
.extension() .extension()
.map(|e| e == "meta") .map(|e| e == "meta")