diff --git a/crates/bevy_asset/Cargo.toml b/crates/bevy_asset/Cargo.toml index 60cbdf4210..b5cf075ab2 100644 --- a/crates/bevy_asset/Cargo.toml +++ b/crates/bevy_asset/Cargo.toml @@ -44,7 +44,11 @@ blake3 = "1.5" parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] } ron = "0.8" serde = { version = "1", features = ["derive"] } -thiserror = "1.0" +derive_more = { version = "1", default-features = false, features = [ + "error", + "from", + "display", +] } uuid = { version = "1.0", features = ["v4"] } [target.'cfg(target_os = "android")'.dependencies] diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 3c33aa43fa..5f4a053846 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -11,8 +11,8 @@ use bevy_reflect::{Reflect, TypePath}; use bevy_utils::HashMap; use core::{any::TypeId, iter::Enumerate, marker::PhantomData, sync::atomic::AtomicU32}; use crossbeam_channel::{Receiver, Sender}; +use derive_more::derive::{Display, Error}; use serde::{Deserialize, Serialize}; -use thiserror::Error; use uuid::Uuid; /// A generational runtime-only identifier for a specific [`Asset`] stored in [`Assets`]. This is optimized for efficient runtime @@ -613,8 +613,8 @@ impl<'a, A: Asset> Iterator for AssetsMutIterator<'a, A> { } } -#[derive(Error, Debug)] -#[error("AssetIndex {index:?} has an invalid generation. The current generation is: '{current_generation}'.")] +#[derive(Error, Display, Debug)] +#[display("AssetIndex {index:?} has an invalid generation. The current generation is: '{current_generation}'.")] pub struct InvalidGenerationError { index: AssetIndex, current_generation: u32, diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index 08e10e8e62..4ecc24c294 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -10,8 +10,8 @@ use core::{ hash::{Hash, Hasher}, }; use crossbeam_channel::{Receiver, Sender}; +use derive_more::derive::{Display, Error}; use disqualified::ShortName; -use thiserror::Error; use uuid::Uuid; /// Provides [`Handle`] and [`UntypedHandle`] _for a specific asset type_. @@ -503,11 +503,11 @@ impl TryFrom for Handle { } /// Errors preventing the conversion of to/from an [`UntypedHandle`] and a [`Handle`]. -#[derive(Error, Debug, PartialEq, Clone)] +#[derive(Error, Display, Debug, PartialEq, Clone)] #[non_exhaustive] pub enum UntypedAssetConversionError { /// Caused when trying to convert an [`UntypedHandle`] into a [`Handle`] of the wrong type. - #[error( + #[display( "This UntypedHandle is for {found:?} and cannot be converted into a Handle<{expected:?}>" )] TypeIdMismatch { expected: TypeId, found: TypeId }, diff --git a/crates/bevy_asset/src/id.rs b/crates/bevy_asset/src/id.rs index 1cca57278e..245b3d4fcd 100644 --- a/crates/bevy_asset/src/id.rs +++ b/crates/bevy_asset/src/id.rs @@ -9,7 +9,7 @@ use core::{ hash::Hash, marker::PhantomData, }; -use thiserror::Error; +use derive_more::derive::{Display, Error, From}; /// A unique runtime-only identifier for an [`Asset`]. This is cheap to [`Copy`]/[`Clone`] and is not directly tied to the /// lifetime of the Asset. This means it _can_ point to an [`Asset`] that no longer exists. @@ -17,7 +17,7 @@ use thiserror::Error; /// For an identifier tied to the lifetime of an asset, see [`Handle`](`crate::Handle`). /// /// For an "untyped" / "generic-less" id, see [`UntypedAssetId`]. -#[derive(Reflect, Serialize, Deserialize)] +#[derive(Reflect, Serialize, Deserialize, From)] pub enum AssetId { /// A small / efficient runtime identifier that can be used to efficiently look up an asset stored in [`Assets`]. This is /// the "default" identifier used for assets. The alternative(s) (ex: [`AssetId::Uuid`]) will only be used if assets are @@ -154,13 +154,6 @@ impl From for AssetId { } } -impl From for AssetId { - #[inline] - fn from(value: Uuid) -> Self { - Self::Uuid { uuid: value } - } -} - /// An "untyped" / "generic-less" [`Asset`] identifier that behaves much like [`AssetId`], but stores the [`Asset`] type /// information at runtime instead of compile-time. This increases the size of the type, but it enables storing asset ids /// across asset types together and enables comparisons between them. @@ -310,7 +303,7 @@ impl PartialOrd for UntypedAssetId { /// Do not _ever_ use this across asset types for comparison. /// [`InternalAssetId`] contains no type information and will happily collide /// with indices across types. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, PartialOrd, Ord, From)] pub(crate) enum InternalAssetId { Index(AssetIndex), Uuid(Uuid), @@ -337,18 +330,6 @@ impl InternalAssetId { } } -impl From for InternalAssetId { - fn from(value: AssetIndex) -> Self { - Self::Index(value) - } -} - -impl From for InternalAssetId { - fn from(value: Uuid) -> Self { - Self::Uuid(value) - } -} - // Cross Operations impl PartialEq for AssetId { @@ -417,11 +398,11 @@ impl TryFrom for AssetId { } /// Errors preventing the conversion of to/from an [`UntypedAssetId`] and an [`AssetId`]. -#[derive(Error, Debug, PartialEq, Clone)] +#[derive(Error, Display, Debug, PartialEq, Clone)] #[non_exhaustive] pub enum UntypedAssetIdConversionError { /// Caused when trying to convert an [`UntypedAssetId`] into an [`AssetId`] of the wrong type. - #[error("This UntypedAssetId is for {found:?} and cannot be converted into an AssetId<{expected:?}>")] + #[display("This UntypedAssetId is for {found:?} and cannot be converted into an AssetId<{expected:?}>")] TypeIdMismatch { expected: TypeId, found: TypeId }, } diff --git a/crates/bevy_asset/src/io/mod.rs b/crates/bevy_asset/src/io/mod.rs index 47ca38b685..735c7527ca 100644 --- a/crates/bevy_asset/src/io/mod.rs +++ b/crates/bevy_asset/src/io/mod.rs @@ -28,25 +28,27 @@ use core::{ pin::Pin, task::{Context, Poll}, }; +use derive_more::derive::{Display, Error, From}; use futures_io::{AsyncRead, AsyncWrite}; use futures_lite::{ready, Stream}; use std::path::{Path, PathBuf}; -use thiserror::Error; /// Errors that occur while loading assets. -#[derive(Error, Debug, Clone)] +#[derive(Error, Display, Debug, Clone)] pub enum AssetReaderError { /// Path not found. - #[error("Path not found: {0}")] + #[display("Path not found: {}", _0.display())] + #[error(ignore)] NotFound(PathBuf), /// Encountered an I/O error while loading an asset. - #[error("Encountered an I/O error while loading asset: {0}")] + #[display("Encountered an I/O error while loading asset: {_0}")] Io(Arc), /// The HTTP request completed but returned an unhandled [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status). /// If the request fails before getting a status code (e.g. request timeout, interrupted connection, etc), expect [`AssetReaderError::Io`]. - #[error("Encountered HTTP status {0:?} when loading asset")] + #[display("Encountered HTTP status {_0:?} when loading asset")] + #[error(ignore)] HttpError(u16), } @@ -296,11 +298,11 @@ pub type Writer = dyn AsyncWrite + Unpin + Send + Sync; pub type PathStream = dyn Stream + Unpin + Send; /// Errors that occur while loading assets. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub enum AssetWriterError { /// Encountered an I/O error while loading an asset. - #[error("encountered an io error while loading asset: {0}")] - Io(#[from] std::io::Error), + #[display("encountered an io error while loading asset: {_0}")] + Io(std::io::Error), } /// Preforms write operations on an asset storage. [`AssetWriter`] exposes a "virtual filesystem" diff --git a/crates/bevy_asset/src/io/source.rs b/crates/bevy_asset/src/io/source.rs index 4af5b377d2..c1185a6495 100644 --- a/crates/bevy_asset/src/io/source.rs +++ b/crates/bevy_asset/src/io/source.rs @@ -10,7 +10,7 @@ use bevy_utils::{ Duration, HashMap, }; use core::{fmt::Display, hash::Hash}; -use thiserror::Error; +use derive_more::derive::{Display, Error}; use super::{ErasedAssetReader, ErasedAssetWriter}; @@ -629,23 +629,27 @@ impl AssetSources { } /// An error returned when an [`AssetSource`] does not exist for a given id. -#[derive(Error, Debug, Clone, PartialEq, Eq)] -#[error("Asset Source '{0}' does not exist")] +#[derive(Error, Display, Debug, Clone, PartialEq, Eq)] +#[display("Asset Source '{_0}' does not exist")] +#[error(ignore)] pub struct MissingAssetSourceError(AssetSourceId<'static>); /// An error returned when an [`AssetWriter`](crate::io::AssetWriter) does not exist for a given id. -#[derive(Error, Debug, Clone)] -#[error("Asset Source '{0}' does not have an AssetWriter.")] +#[derive(Error, Display, Debug, Clone)] +#[display("Asset Source '{_0}' does not have an AssetWriter.")] +#[error(ignore)] pub struct MissingAssetWriterError(AssetSourceId<'static>); /// An error returned when a processed [`AssetReader`](crate::io::AssetReader) does not exist for a given id. -#[derive(Error, Debug, Clone, PartialEq, Eq)] -#[error("Asset Source '{0}' does not have a processed AssetReader.")] +#[derive(Error, Display, Debug, Clone, PartialEq, Eq)] +#[display("Asset Source '{_0}' does not have a processed AssetReader.")] +#[error(ignore)] pub struct MissingProcessedAssetReaderError(AssetSourceId<'static>); /// An error returned when a processed [`AssetWriter`](crate::io::AssetWriter) does not exist for a given id. -#[derive(Error, Debug, Clone)] -#[error("Asset Source '{0}' does not have a processed AssetWriter.")] +#[derive(Error, Display, Debug, Clone)] +#[display("Asset Source '{_0}' does not have a processed AssetWriter.")] +#[error(ignore)] pub struct MissingProcessedAssetWriterError(AssetSourceId<'static>); const MISSING_DEFAULT_SOURCE: &str = diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index c1ffb6b293..5813cb3918 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -631,9 +631,9 @@ mod tests { use bevy_log::LogPlugin; use bevy_reflect::TypePath; use bevy_utils::{Duration, HashMap}; + use derive_more::derive::{Display, Error, From}; use serde::{Deserialize, Serialize}; use std::path::Path; - use thiserror::Error; #[derive(Asset, TypePath, Debug, Default)] pub struct CoolText { @@ -661,14 +661,14 @@ mod tests { #[derive(Default)] pub struct CoolTextLoader; - #[derive(Error, Debug)] + #[derive(Error, Display, Debug, From)] pub enum CoolTextLoaderError { - #[error("Could not load dependency: {dependency}")] + #[display("Could not load dependency: {dependency}")] CannotLoadDependency { dependency: AssetPath<'static> }, - #[error("A RON error occurred during loading")] - RonSpannedError(#[from] ron::error::SpannedError), - #[error("An IO error occurred during loading")] - Io(#[from] std::io::Error), + #[display("A RON error occurred during loading")] + RonSpannedError(ron::error::SpannedError), + #[display("An IO error occurred during loading")] + Io(std::io::Error), } impl AssetLoader for CoolTextLoader { diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index a0bd8ce129..7192fe265c 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -10,11 +10,11 @@ use atomicow::CowArc; use bevy_ecs::world::World; use bevy_utils::{BoxedFuture, ConditionalSendFuture, HashMap, HashSet}; use core::any::{Any, TypeId}; +use derive_more::derive::{Display, Error, From}; use downcast_rs::{impl_downcast, Downcast}; use ron::error::SpannedError; use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf}; -use thiserror::Error; /// Loads an [`Asset`] from a given byte [`Reader`]. This can accept [`AssetLoader::Settings`], which configure how the [`Asset`] /// should be loaded. @@ -295,19 +295,20 @@ impl AssetContainer for A { /// /// [`NestedLoader::load`]: crate::NestedLoader::load /// [immediately]: crate::Immediate -#[derive(Error, Debug)] -#[error("Failed to load dependency {dependency:?} {error}")] +#[derive(Error, Display, Debug)] +#[display("Failed to load dependency {dependency:?} {error}")] pub struct LoadDirectError { pub dependency: AssetPath<'static>, pub error: AssetLoadError, } /// An error that occurs while deserializing [`AssetMeta`]. -#[derive(Error, Debug, Clone, PartialEq, Eq)] +#[derive(Error, Display, Debug, Clone, PartialEq, Eq, From)] pub enum DeserializeMetaError { - #[error("Failed to deserialize asset meta: {0:?}")] - DeserializeSettings(#[from] SpannedError), - #[error("Failed to deserialize minimal asset meta: {0:?}")] + #[display("Failed to deserialize asset meta: {_0:?}")] + DeserializeSettings(SpannedError), + #[display("Failed to deserialize minimal asset meta: {_0:?}")] + #[from(ignore)] DeserializeMinimal(SpannedError), } @@ -572,23 +573,18 @@ impl<'a> LoadContext<'a> { } /// An error produced when calling [`LoadContext::read_asset_bytes`] -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub enum ReadAssetBytesError { - #[error(transparent)] - DeserializeMetaError(#[from] DeserializeMetaError), - #[error(transparent)] - AssetReaderError(#[from] AssetReaderError), - #[error(transparent)] - MissingAssetSourceError(#[from] MissingAssetSourceError), - #[error(transparent)] - MissingProcessedAssetReaderError(#[from] MissingProcessedAssetReaderError), + DeserializeMetaError(DeserializeMetaError), + AssetReaderError(AssetReaderError), + MissingAssetSourceError(MissingAssetSourceError), + MissingProcessedAssetReaderError(MissingProcessedAssetReaderError), /// Encountered an I/O error while loading an asset. - #[error("Encountered an io error while loading asset at `{path}`: {source}")] + #[display("Encountered an io error while loading asset at `{}`: {source}", path.display())] Io { path: PathBuf, - #[source] source: std::io::Error, }, - #[error("The LoadContext for this read_asset_bytes call requires hash metadata, but it was not provided. This is likely an internal implementation error.")] + #[display("The LoadContext for this read_asset_bytes call requires hash metadata, but it was not provided. This is likely an internal implementation error.")] MissingAssetHash, } diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index 3bbb643650..c86a190fe1 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -6,9 +6,9 @@ use core::{ hash::Hash, ops::Deref, }; +use derive_more::derive::{Display, Error}; use serde::{de::Visitor, Deserialize, Serialize}; use std::path::{Path, PathBuf}; -use thiserror::Error; /// Represents a path to an asset in a "virtual filesystem". /// @@ -76,19 +76,19 @@ impl<'a> Display for AssetPath<'a> { } /// An error that occurs when parsing a string type to create an [`AssetPath`] fails, such as during [`AssetPath::parse`]. -#[derive(Error, Debug, PartialEq, Eq)] +#[derive(Error, Display, Debug, PartialEq, Eq)] pub enum ParseAssetPathError { /// Error that occurs when the [`AssetPath::source`] section of a path string contains the [`AssetPath::label`] delimiter `#`. E.g. `bad#source://file.test`. - #[error("Asset source must not contain a `#` character")] + #[display("Asset source must not contain a `#` character")] InvalidSourceSyntax, /// Error that occurs when the [`AssetPath::label`] section of a path string contains the [`AssetPath::source`] delimiter `://`. E.g. `source://file.test#bad://label`. - #[error("Asset label must not contain a `://` substring")] + #[display("Asset label must not contain a `://` substring")] InvalidLabelSyntax, /// Error that occurs when a path string has an [`AssetPath::source`] delimiter `://` with no characters preceding it. E.g. `://file.test`. - #[error("Asset source must be at least one character. Either specify the source before the '://' or remove the `://`")] + #[display("Asset source must be at least one character. Either specify the source before the '://' or remove the `://`")] MissingSource, /// Error that occurs when a path string has an [`AssetPath::label`] delimiter `#` with no characters succeeding it. E.g. `file.test#` - #[error("Asset label must be at least one character. Either specify the label after the '#' or remove the '#'")] + #[display("Asset label must be at least one character. Either specify the label after the '#' or remove the '#'")] MissingLabel, } diff --git a/crates/bevy_asset/src/processor/log.rs b/crates/bevy_asset/src/processor/log.rs index 2649b815d8..d0582d5dbd 100644 --- a/crates/bevy_asset/src/processor/log.rs +++ b/crates/bevy_asset/src/processor/log.rs @@ -1,9 +1,9 @@ use crate::AssetPath; use async_fs::File; use bevy_utils::{tracing::error, HashSet}; +use derive_more::derive::{Display, Error, From}; use futures_lite::{AsyncReadExt, AsyncWriteExt}; use std::path::PathBuf; -use thiserror::Error; /// An in-memory representation of a single [`ProcessorTransactionLog`] entry. #[derive(Debug)] @@ -24,17 +24,18 @@ pub struct ProcessorTransactionLog { } /// An error that occurs when reading from the [`ProcessorTransactionLog`] fails. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub enum ReadLogError { - #[error("Encountered an invalid log line: '{0}'")] + #[display("Encountered an invalid log line: '{_0}'")] + #[error(ignore)] InvalidLine(String), - #[error("Failed to read log file: {0}")] - Io(#[from] futures_io::Error), + #[display("Failed to read log file: {_0}")] + Io(futures_io::Error), } /// An error that occurs when writing to the [`ProcessorTransactionLog`] fails. -#[derive(Error, Debug)] -#[error( +#[derive(Error, Display, Debug)] +#[display( "Failed to write {log_entry:?} to the asset processor log. This is not recoverable. {error}" )] pub struct WriteLogError { @@ -43,24 +44,27 @@ pub struct WriteLogError { } /// An error that occurs when validating the [`ProcessorTransactionLog`] fails. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub enum ValidateLogError { - #[error("Encountered an unrecoverable error. All assets will be reprocessed.")] + #[display("Encountered an unrecoverable error. All assets will be reprocessed.")] UnrecoverableError, - #[error(transparent)] - ReadLogError(#[from] ReadLogError), - #[error("Encountered a duplicate process asset transaction: {0:?}")] + ReadLogError(ReadLogError), + #[display("Encountered a duplicate process asset transaction: {_0:?}")] + #[error(ignore)] EntryErrors(Vec), } /// An error that occurs when validating individual [`ProcessorTransactionLog`] entries. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug)] pub enum LogEntryError { - #[error("Encountered a duplicate process asset transaction: {0}")] + #[display("Encountered a duplicate process asset transaction: {_0}")] + #[error(ignore)] DuplicateTransaction(AssetPath<'static>), - #[error("A transaction was ended that never started {0}")] + #[display("A transaction was ended that never started {_0}")] + #[error(ignore)] EndedMissingTransaction(AssetPath<'static>), - #[error("An asset started processing but never finished: {0}")] + #[display("An asset started processing but never finished: {_0}")] + #[error(ignore)] UnfinishedTransaction(AssetPath<'static>), } diff --git a/crates/bevy_asset/src/processor/mod.rs b/crates/bevy_asset/src/processor/mod.rs index 0030b890d8..7d63f255f4 100644 --- a/crates/bevy_asset/src/processor/mod.rs +++ b/crates/bevy_asset/src/processor/mod.rs @@ -68,11 +68,11 @@ use bevy_utils::{ tracing::{info_span, instrument::Instrument}, ConditionalSendFuture, }; +use derive_more::derive::{Display, Error}; use futures_io::ErrorKind; use futures_lite::{AsyncReadExt, AsyncWriteExt, StreamExt}; use parking_lot::RwLock; use std::path::{Path, PathBuf}; -use thiserror::Error; /// A "background" asset processor that reads asset values from a source [`AssetSource`] (which corresponds to an [`AssetReader`](crate::io::AssetReader) / [`AssetWriter`](crate::io::AssetWriter) pair), /// processes them in some way, and writes them to a destination [`AssetSource`]. @@ -1413,12 +1413,10 @@ pub enum ProcessorState { } /// An error that occurs when initializing the [`AssetProcessor`]. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug)] pub enum InitializeError { - #[error(transparent)] FailedToReadSourcePaths(AssetReaderError), - #[error(transparent)] FailedToReadDestinationPaths(AssetReaderError), - #[error("Failed to validate asset log: {0}")] + #[display("Failed to validate asset log: {_0}")] ValidateLogError(ValidateLogError), } diff --git a/crates/bevy_asset/src/processor/process.rs b/crates/bevy_asset/src/processor/process.rs index 785b23f99c..b9d2cd3b47 100644 --- a/crates/bevy_asset/src/processor/process.rs +++ b/crates/bevy_asset/src/processor/process.rs @@ -12,8 +12,8 @@ use crate::{ }; use bevy_utils::{BoxedFuture, ConditionalSendFuture}; use core::marker::PhantomData; +use derive_more::derive::{Display, Error, From}; use serde::{Deserialize, Serialize}; -use thiserror::Error; /// Asset "processor" logic that reads input asset bytes (stored on [`ProcessContext`]), processes the value in some way, /// and then writes the final processed bytes with [`Writer`]. The resulting bytes must be loadable with the given [`Process::OutputLoader`]. @@ -126,46 +126,46 @@ pub type LoadAndSaveSettings = LoadTransformAndSaveSettings; /// An error that is encountered during [`Process::process`]. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub enum ProcessError { - #[error(transparent)] - MissingAssetLoaderForExtension(#[from] MissingAssetLoaderForExtensionError), - #[error(transparent)] - MissingAssetLoaderForTypeName(#[from] MissingAssetLoaderForTypeNameError), - #[error("The processor '{0}' does not exist")] + MissingAssetLoaderForExtension(MissingAssetLoaderForExtensionError), + MissingAssetLoaderForTypeName(MissingAssetLoaderForTypeNameError), + #[display("The processor '{_0}' does not exist")] + #[error(ignore)] + #[from(ignore)] MissingProcessor(String), - #[error("Encountered an AssetReader error for '{path}': {err}")] + #[display("Encountered an AssetReader error for '{path}': {err}")] + #[from(ignore)] AssetReaderError { path: AssetPath<'static>, err: AssetReaderError, }, - #[error("Encountered an AssetWriter error for '{path}': {err}")] + #[display("Encountered an AssetWriter error for '{path}': {err}")] + #[from(ignore)] AssetWriterError { path: AssetPath<'static>, err: AssetWriterError, }, - #[error(transparent)] - MissingAssetWriterError(#[from] MissingAssetWriterError), - #[error(transparent)] - MissingProcessedAssetReaderError(#[from] MissingProcessedAssetReaderError), - #[error(transparent)] - MissingProcessedAssetWriterError(#[from] MissingProcessedAssetWriterError), - #[error("Failed to read asset metadata for {path}: {err}")] + MissingAssetWriterError(MissingAssetWriterError), + MissingProcessedAssetReaderError(MissingProcessedAssetReaderError), + MissingProcessedAssetWriterError(MissingProcessedAssetWriterError), + #[display("Failed to read asset metadata for {path}: {err}")] + #[from(ignore)] ReadAssetMetaError { path: AssetPath<'static>, err: AssetReaderError, }, - #[error(transparent)] - DeserializeMetaError(#[from] DeserializeMetaError), - #[error(transparent)] - AssetLoadError(#[from] AssetLoadError), - #[error("The wrong meta type was passed into a processor. This is probably an internal implementation error.")] + DeserializeMetaError(DeserializeMetaError), + AssetLoadError(AssetLoadError), + #[display("The wrong meta type was passed into a processor. This is probably an internal implementation error.")] WrongMetaType, - #[error("Encountered an error while saving the asset: {0}")] - AssetSaveError(#[from] Box), - #[error("Encountered an error while transforming the asset: {0}")] + #[display("Encountered an error while saving the asset: {_0}")] + #[from(ignore)] + AssetSaveError(Box), + #[display("Encountered an error while transforming the asset: {_0}")] + #[from(ignore)] AssetTransformError(Box), - #[error("Assets without extensions are not supported.")] + #[display("Assets without extensions are not supported.")] ExtensionRequired, } diff --git a/crates/bevy_asset/src/server/info.rs b/crates/bevy_asset/src/server/info.rs index 85b3d02fa5..5fd0193c77 100644 --- a/crates/bevy_asset/src/server/info.rs +++ b/crates/bevy_asset/src/server/info.rs @@ -10,8 +10,8 @@ use bevy_tasks::Task; use bevy_utils::{tracing::warn, Entry, HashMap, HashSet, TypeIdMap}; use core::any::TypeId; use crossbeam_channel::Sender; +use derive_more::derive::{Display, Error, From}; use either::Either; -use thiserror::Error; #[derive(Debug)] pub(crate) struct AssetInfo { @@ -755,16 +755,16 @@ pub(crate) enum HandleLoadingMode { Force, } -#[derive(Error, Debug)] -#[error("Cannot allocate a handle because no handle provider exists for asset type {0:?}")] +#[derive(Error, Display, Debug)] +#[display("Cannot allocate a handle because no handle provider exists for asset type {_0:?}")] +#[error(ignore)] pub struct MissingHandleProviderError(TypeId); /// An error encountered during [`AssetInfos::get_or_create_path_handle_internal`]. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub(crate) enum GetOrCreateHandleInternalError { - #[error(transparent)] - MissingHandleProviderError(#[from] MissingHandleProviderError), - #[error("Handle does not exist but TypeId was not specified.")] + MissingHandleProviderError(MissingHandleProviderError), + #[display("Handle does not exist but TypeId was not specified.")] HandleMissingButTypeIdNotSpecified, } diff --git a/crates/bevy_asset/src/server/loaders.rs b/crates/bevy_asset/src/server/loaders.rs index 8c63a2306e..3850a7fb78 100644 --- a/crates/bevy_asset/src/server/loaders.rs +++ b/crates/bevy_asset/src/server/loaders.rs @@ -5,17 +5,14 @@ use crate::{ use alloc::sync::Arc; use async_broadcast::RecvError; use bevy_tasks::IoTaskPool; -use bevy_utils::{ - tracing::{error, warn}, - HashMap, TypeIdMap, -}; +use bevy_utils::{tracing::warn, HashMap, TypeIdMap}; #[cfg(feature = "trace")] use bevy_utils::{ tracing::{info_span, instrument::Instrument}, ConditionalSendFuture, }; use core::any::TypeId; -use thiserror::Error; +use derive_more::derive::{Display, Error, From}; #[derive(Default)] pub(crate) struct AssetLoaders { @@ -278,10 +275,9 @@ impl AssetLoaders { } } -#[derive(Error, Debug, Clone)] +#[derive(Error, Display, Debug, Clone, From)] pub(crate) enum GetLoaderError { - #[error(transparent)] - CouldNotResolve(#[from] RecvError), + CouldNotResolve(RecvError), } #[derive(Clone)] diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index a56e653818..acf351843d 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -31,13 +31,13 @@ use core::{ panic::AssertUnwindSafe, }; use crossbeam_channel::{Receiver, Sender}; +use derive_more::derive::{Display, Error, From}; use either::Either; use futures_lite::{FutureExt, StreamExt}; use info::*; use loaders::*; use parking_lot::RwLock; use std::path::{Path, PathBuf}; -use thiserror::Error; /// Loads and tracks the state of [`Asset`] values from a configured [`AssetReader`](crate::io::AssetReader). This can be used to kick off new asset loads and /// retrieve their current load states. @@ -1532,55 +1532,53 @@ pub enum RecursiveDependencyLoadState { } /// An error that occurs during an [`Asset`] load. -#[derive(Error, Debug, Clone, PartialEq, Eq)] +#[derive(Error, Display, Debug, Clone, PartialEq, Eq, From)] pub enum AssetLoadError { - #[error("Requested handle of type {requested:?} for asset '{path}' does not match actual asset type '{actual_asset_name}', which used loader '{loader_name}'")] + #[display("Requested handle of type {requested:?} for asset '{path}' does not match actual asset type '{actual_asset_name}', which used loader '{loader_name}'")] RequestedHandleTypeMismatch { path: AssetPath<'static>, requested: TypeId, actual_asset_name: &'static str, loader_name: &'static str, }, - #[error("Could not find an asset loader matching: Loader Name: {loader_name:?}; Asset Type: {loader_name:?}; Extension: {extension:?}; Path: {asset_path:?};")] + #[display("Could not find an asset loader matching: Loader Name: {loader_name:?}; Asset Type: {loader_name:?}; Extension: {extension:?}; Path: {asset_path:?};")] MissingAssetLoader { loader_name: Option, asset_type_id: Option, extension: Option, asset_path: Option, }, - #[error(transparent)] - MissingAssetLoaderForExtension(#[from] MissingAssetLoaderForExtensionError), - #[error(transparent)] - MissingAssetLoaderForTypeName(#[from] MissingAssetLoaderForTypeNameError), - #[error(transparent)] - MissingAssetLoaderForTypeIdError(#[from] MissingAssetLoaderForTypeIdError), - #[error(transparent)] - AssetReaderError(#[from] AssetReaderError), - #[error(transparent)] - MissingAssetSourceError(#[from] MissingAssetSourceError), - #[error(transparent)] - MissingProcessedAssetReaderError(#[from] MissingProcessedAssetReaderError), - #[error("Encountered an error while reading asset metadata bytes")] + MissingAssetLoaderForExtension(MissingAssetLoaderForExtensionError), + MissingAssetLoaderForTypeName(MissingAssetLoaderForTypeNameError), + MissingAssetLoaderForTypeIdError(MissingAssetLoaderForTypeIdError), + AssetReaderError(AssetReaderError), + MissingAssetSourceError(MissingAssetSourceError), + MissingProcessedAssetReaderError(MissingProcessedAssetReaderError), + #[display("Encountered an error while reading asset metadata bytes")] AssetMetaReadError, - #[error("Failed to deserialize meta for asset {path}: {error}")] + #[display("Failed to deserialize meta for asset {path}: {error}")] DeserializeMeta { path: AssetPath<'static>, error: Box, }, - #[error("Asset '{path}' is configured to be processed. It cannot be loaded directly.")] - CannotLoadProcessedAsset { path: AssetPath<'static> }, - #[error("Asset '{path}' is configured to be ignored. It cannot be loaded.")] - CannotLoadIgnoredAsset { path: AssetPath<'static> }, - #[error("Failed to load asset '{path}', asset loader '{loader_name}' panicked")] + #[display("Asset '{path}' is configured to be processed. It cannot be loaded directly.")] + #[from(ignore)] + CannotLoadProcessedAsset { + path: AssetPath<'static>, + }, + #[display("Asset '{path}' is configured to be ignored. It cannot be loaded.")] + #[from(ignore)] + CannotLoadIgnoredAsset { + path: AssetPath<'static>, + }, + #[display("Failed to load asset '{path}', asset loader '{loader_name}' panicked")] AssetLoaderPanic { path: AssetPath<'static>, loader_name: &'static str, }, - #[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: {}", + AssetLoaderError(AssetLoaderError), + AddAsyncError(AddAsyncError), + #[display("The file at '{}' does not contain the labeled asset '{}'; it contains the following {} assets: {}", base_path, label, all_labels.len(), @@ -1592,8 +1590,8 @@ pub enum AssetLoadError { }, } -#[derive(Error, Debug, Clone)] -#[error("Failed to load asset '{path}' with asset loader '{loader_name}': {error}")] +#[derive(Error, Display, Debug, Clone)] +#[display("Failed to load asset '{path}' with asset loader '{loader_name}': {error}")] pub struct AssetLoaderError { path: AssetPath<'static>, loader_name: &'static str, @@ -1618,8 +1616,8 @@ impl AssetLoaderError { } } -#[derive(Error, Debug, Clone)] -#[error("An error occurred while resolving an asset added by `add_async`: {error}")] +#[derive(Error, Display, Debug, Clone)] +#[display("An error occurred while resolving an asset added by `add_async`: {error}")] pub struct AddAsyncError { error: Arc, } @@ -1635,22 +1633,22 @@ impl PartialEq for AddAsyncError { 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))] +#[derive(Error, Display, Debug, Clone, PartialEq, Eq)] +#[display("no `AssetLoader` found{}", format_missing_asset_ext(extensions))] pub struct MissingAssetLoaderForExtensionError { extensions: Vec, } /// An error that occurs when an [`AssetLoader`] is not registered for a given [`std::any::type_name`]. -#[derive(Error, Debug, Clone, PartialEq, Eq)] -#[error("no `AssetLoader` found with the name '{type_name}'")] +#[derive(Error, Display, Debug, Clone, PartialEq, Eq)] +#[display("no `AssetLoader` found with the name '{type_name}'")] pub struct MissingAssetLoaderForTypeNameError { type_name: String, } /// An error that occurs when an [`AssetLoader`] is not registered for a given [`Asset`] [`TypeId`]. -#[derive(Error, Debug, Clone, PartialEq, Eq)] -#[error("no `AssetLoader` found with the ID '{type_id:?}'")] +#[derive(Error, Display, Debug, Clone, PartialEq, Eq)] +#[display("no `AssetLoader` found with the ID '{type_id:?}'")] pub struct MissingAssetLoaderForTypeIdError { pub type_id: TypeId, }