Use BevyError for AssetLoader::Error (#19478)
# Objective Allow using `BevyResult` in `AssetLoader`s for consistency. Currently, it converts errors into `Box<dyn core::error::Error + Send + Sync + 'static>`, which is essentially a `BevyError` without the optional backtrace functionality. ## Solution I don't think needs a migration guide as any type that satisfies `Into<Box<dyn core::error::Error + Send + Sync + 'static>>` also satisfies `Into<BevyError>`.
This commit is contained in:
parent
7a7bff8c17
commit
5561b40bdf
@ -12,7 +12,7 @@ use alloc::{
|
|||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
use atomicow::CowArc;
|
use atomicow::CowArc;
|
||||||
use bevy_ecs::world::World;
|
use bevy_ecs::{error::BevyError, world::World};
|
||||||
use bevy_platform::collections::{HashMap, HashSet};
|
use bevy_platform::collections::{HashMap, HashSet};
|
||||||
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
|
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
|
||||||
use core::any::{Any, TypeId};
|
use core::any::{Any, TypeId};
|
||||||
@ -34,7 +34,7 @@ pub trait AssetLoader: Send + Sync + 'static {
|
|||||||
/// The settings type used by this [`AssetLoader`].
|
/// The settings type used by this [`AssetLoader`].
|
||||||
type Settings: Settings + Default + Serialize + for<'a> Deserialize<'a>;
|
type Settings: Settings + Default + Serialize + for<'a> Deserialize<'a>;
|
||||||
/// The type of [error](`std::error::Error`) which could be encountered by this loader.
|
/// The type of [error](`std::error::Error`) which could be encountered by this loader.
|
||||||
type Error: Into<Box<dyn core::error::Error + Send + Sync + 'static>>;
|
type Error: Into<BevyError>;
|
||||||
/// Asynchronously loads [`AssetLoader::Asset`] (and any other labeled assets) from the bytes provided by [`Reader`].
|
/// Asynchronously loads [`AssetLoader::Asset`] (and any other labeled assets) from the bytes provided by [`Reader`].
|
||||||
fn load(
|
fn load(
|
||||||
&self,
|
&self,
|
||||||
@ -58,10 +58,7 @@ pub trait ErasedAssetLoader: Send + Sync + 'static {
|
|||||||
reader: &'a mut dyn Reader,
|
reader: &'a mut dyn Reader,
|
||||||
meta: &'a dyn AssetMetaDyn,
|
meta: &'a dyn AssetMetaDyn,
|
||||||
load_context: LoadContext<'a>,
|
load_context: LoadContext<'a>,
|
||||||
) -> BoxedFuture<
|
) -> BoxedFuture<'a, Result<ErasedLoadedAsset, BevyError>>;
|
||||||
'a,
|
|
||||||
Result<ErasedLoadedAsset, Box<dyn core::error::Error + Send + Sync + 'static>>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
/// Returns a list of extensions supported by this asset loader, without the preceding dot.
|
/// Returns a list of extensions supported by this asset loader, without the preceding dot.
|
||||||
fn extensions(&self) -> &[&str];
|
fn extensions(&self) -> &[&str];
|
||||||
@ -89,10 +86,7 @@ where
|
|||||||
reader: &'a mut dyn Reader,
|
reader: &'a mut dyn Reader,
|
||||||
meta: &'a dyn AssetMetaDyn,
|
meta: &'a dyn AssetMetaDyn,
|
||||||
mut load_context: LoadContext<'a>,
|
mut load_context: LoadContext<'a>,
|
||||||
) -> BoxedFuture<
|
) -> BoxedFuture<'a, Result<ErasedLoadedAsset, BevyError>> {
|
||||||
'a,
|
|
||||||
Result<ErasedLoadedAsset, Box<dyn core::error::Error + Send + Sync + 'static>>,
|
|
||||||
> {
|
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let settings = meta
|
let settings = meta
|
||||||
.loader_settings()
|
.loader_settings()
|
||||||
|
@ -1945,7 +1945,7 @@ pub enum AssetLoadError {
|
|||||||
pub struct AssetLoaderError {
|
pub struct AssetLoaderError {
|
||||||
path: AssetPath<'static>,
|
path: AssetPath<'static>,
|
||||||
loader_name: &'static str,
|
loader_name: &'static str,
|
||||||
error: Arc<dyn core::error::Error + Send + Sync + 'static>,
|
error: Arc<BevyError>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssetLoaderError {
|
impl AssetLoaderError {
|
||||||
|
Loading…
Reference in New Issue
Block a user