diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index 46e334ec66..a75fb9a4a4 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -718,9 +718,9 @@ impl AssetServer { /// /// After the asset has been fully loaded, it will show up in the relevant [`Assets`] storage. #[must_use = "not using the returned strong handle may result in the unexpected release of the asset"] - pub fn add_async( + pub fn add_async( &self, - future: impl Future> + Send + 'static, + future: impl Future> + Send + 'static, ) -> Handle { let handle = self .data @@ -741,12 +741,15 @@ impl AssetServer { .unwrap(); } Err(error) => { + let error = AddAsyncError { + error: Arc::new(error), + }; error!("{error}"); event_sender .send(InternalAssetEvent::Failed { id, path: Default::default(), - error, + error: AssetLoadError::AddAsyncError(error), }) .unwrap(); } @@ -1403,6 +1406,8 @@ pub enum AssetLoadError { CannotLoadIgnoredAsset { path: AssetPath<'static> }, #[error(transparent)] AssetLoaderError(#[from] AssetLoaderError), + #[error(transparent)] + AddAsyncError(#[from] AddAsyncError), #[error("The file at '{}' does not contain the labeled asset '{}'; it contains the following {} assets: {}", base_path, label, @@ -1441,6 +1446,22 @@ impl AssetLoaderError { } } +#[derive(Error, Debug, Clone)] +#[error("An error occurred while resolving an asset added by `add_async`: {error}")] +pub struct AddAsyncError { + error: Arc, +} + +impl PartialEq for AddAsyncError { + /// Equality comparison is not full (only through `TypeId`) + #[inline] + fn eq(&self, other: &Self) -> bool { + self.error.type_id() == other.error.type_id() + } +} + +impl Eq for AddAsyncError {} + /// An error that occurs when an [`AssetLoader`] is not registered for a given extension. #[derive(Error, Debug, Clone, PartialEq, Eq)] #[error("no `AssetLoader` found{}", format_missing_asset_ext(.extensions))]