Skip to content

Commit

Permalink
Deny derive_more error feature and replace it with thiserror
Browse files Browse the repository at this point in the history
  • Loading branch information
bushrat011899 committed Dec 6, 2024
1 parent 5b1f0b1 commit 78d8f4c
Show file tree
Hide file tree
Showing 103 changed files with 670 additions and 769 deletions.
7 changes: 2 additions & 5 deletions crates/bevy_animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ ron = "0.8"
serde = "1"
blake3 = { version = "1.0" }
downcast-rs = "1.2.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
thiserror = { version = "2", default-features = false }
derive_more = { version = "1", default-features = false, features = ["from"] }
either = "1.13"
thread_local = "1"
uuid = { version = "1.7", features = ["v4"] }
Expand Down
11 changes: 6 additions & 5 deletions crates/bevy_animation/src/gltf_curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use bevy_math::{
vec4, Quat, Vec4, VectorSpace,
};
use bevy_reflect::Reflect;
use derive_more::derive::{Display, Error, From};
use either::Either;
use thiserror::Error;

/// A keyframe-defined curve that "interpolates" by stepping at `t = 1.0` to the next keyframe.
#[derive(Debug, Clone, Reflect)]
Expand Down Expand Up @@ -319,19 +319,20 @@ where
}

/// An error indicating that a multisampling keyframe curve could not be constructed.
#[derive(Debug, Error, Display, From)]
#[display("unable to construct a curve using this data")]
#[derive(Debug, Error)]
#[error("unable to construct a curve using this data")]
pub enum WideKeyframeCurveError {
/// The number of given values was not divisible by a multiple of the number of keyframes.
#[display("number of values ({values_given}) is not divisible by {divisor}")]
#[error("number of values ({values_given}) is not divisible by {divisor}")]
LengthMismatch {
/// The number of values given.
values_given: usize,
/// The number that `values_given` was supposed to be divisible by.
divisor: usize,
},
/// An error was returned by the internal core constructor.
CoreError(ChunkedUnevenCoreError),
#[error(transparent)]
CoreError(#[from] ChunkedUnevenCoreError),
}

impl<T> WideCubicKeyframeCurve<T> {
Expand Down
17 changes: 9 additions & 8 deletions crates/bevy_animation/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ use bevy_ecs::{
};
use bevy_reflect::{prelude::ReflectDefault, Reflect, ReflectSerialize};
use bevy_utils::HashMap;
use derive_more::derive::{Display, Error, From};
use derive_more::derive::From;
use petgraph::{
graph::{DiGraph, NodeIndex},
Direction,
};
use ron::de::SpannedError;
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use thiserror::Error;

use crate::{AnimationClip, AnimationTargetId};

Expand Down Expand Up @@ -237,18 +238,18 @@ pub struct AnimationGraphAssetLoader;

/// Various errors that can occur when serializing or deserializing animation
/// graphs to and from RON, respectively.
#[derive(Error, Display, Debug, From)]
#[derive(Error, Debug)]
pub enum AnimationGraphLoadError {
/// An I/O error occurred.
#[display("I/O")]
Io(io::Error),
#[error("I/O")]
Io(#[from] io::Error),
/// An error occurred in RON serialization or deserialization.
#[display("RON serialization")]
Ron(ron::Error),
#[error("RON serialization")]
Ron(#[from] ron::Error),
/// An error occurred in RON deserialization, and the location of the error
/// is supplied.
#[display("RON serialization")]
SpannedRon(SpannedError),
#[error("RON serialization")]
SpannedRon(#[from] SpannedError),
}

/// Acceleration structures for animation graphs that allows Bevy to evaluate
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.15.0-dev" }

# other
downcast-rs = "1.2.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
thiserror = { version = "2", default-features = false }
variadics_please = "1.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use bevy_ecs::{
use bevy_utils::tracing::info_span;
use bevy_utils::{tracing::debug, HashMap};
use core::{fmt::Debug, num::NonZero, panic::AssertUnwindSafe};
use derive_more::derive::{Display, Error};
use std::{
panic::{catch_unwind, resume_unwind},
process::{ExitCode, Termination},
};
use thiserror::Error;

bevy_ecs::define_label!(
/// A strongly-typed class of labels used to identify an [`App`].
Expand All @@ -32,9 +32,9 @@ pub use bevy_ecs::label::DynEq;
/// A shorthand for `Interned<dyn AppLabel>`.
pub type InternedAppLabel = Interned<dyn AppLabel>;

#[derive(Debug, Error, Display)]
#[derive(Debug, Error)]
pub(crate) enum AppError {
#[display("duplicate plugin {plugin_name:?}")]
#[error("duplicate plugin {plugin_name:?}")]
DuplicatePlugin { plugin_name: String },
}

Expand Down
7 changes: 2 additions & 5 deletions crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ blake3 = "1.5"
parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] }
ron = "0.8"
serde = { version = "1", features = ["derive"] }
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
thiserror = { version = "2", default-features = false }
derive_more = { version = "1", default-features = false, features = ["from"] }
uuid = { version = "1.0", features = ["v4"] }

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -613,8 +613,8 @@ impl<'a, A: Asset> Iterator for AssetsMutIterator<'a, A> {
}
}

#[derive(Error, Display, Debug)]
#[display("AssetIndex {index:?} has an invalid generation. The current generation is: '{current_generation}'.")]
#[derive(Error, Debug)]
#[error("AssetIndex {index:?} has an invalid generation. The current generation is: '{current_generation}'.")]
pub struct InvalidGenerationError {
index: AssetIndex,
current_generation: u32,
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,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_.
Expand Down Expand Up @@ -502,11 +502,11 @@ impl<A: Asset> TryFrom<UntypedHandle> for Handle<A> {
}

/// Errors preventing the conversion of to/from an [`UntypedHandle`] and a [`Handle`].
#[derive(Error, Display, Debug, PartialEq, Clone)]
#[derive(Error, Debug, PartialEq, Clone)]
#[non_exhaustive]
pub enum UntypedAssetConversionError {
/// Caused when trying to convert an [`UntypedHandle`] into a [`Handle`] of the wrong type.
#[display(
#[error(
"This UntypedHandle is for {found:?} and cannot be converted into a Handle<{expected:?}>"
)]
TypeIdMismatch { expected: TypeId, found: TypeId },
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_asset/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use core::{
hash::Hash,
marker::PhantomData,
};
use derive_more::derive::{Display, Error, From};
use derive_more::derive::From;
use thiserror::Error;

/// 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.
Expand Down Expand Up @@ -398,11 +399,11 @@ impl<A: Asset> TryFrom<UntypedAssetId> for AssetId<A> {
}

/// Errors preventing the conversion of to/from an [`UntypedAssetId`] and an [`AssetId`].
#[derive(Error, Display, Debug, PartialEq, Clone)]
#[derive(Error, Debug, PartialEq, Clone)]
#[non_exhaustive]
pub enum UntypedAssetIdConversionError {
/// Caused when trying to convert an [`UntypedAssetId`] into an [`AssetId`] of the wrong type.
#[display("This UntypedAssetId is for {found:?} and cannot be converted into an AssetId<{expected:?}>")]
#[error("This UntypedAssetId is for {found:?} and cannot be converted into an AssetId<{expected:?}>")]
TypeIdMismatch { expected: TypeId, found: TypeId },
}

Expand Down
18 changes: 8 additions & 10 deletions crates/bevy_asset/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,25 @@ 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, Display, Debug, Clone)]
#[derive(Error, Debug, Clone)]
pub enum AssetReaderError {
/// Path not found.
#[display("Path not found: {}", _0.display())]
#[error(ignore)]
#[error("Path not found: {}", _0.display())]
NotFound(PathBuf),

/// Encountered an I/O error while loading an asset.
#[display("Encountered an I/O error while loading asset: {_0}")]
#[error("Encountered an I/O error while loading asset: {0}")]
Io(Arc<std::io::Error>),

/// 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`].
#[display("Encountered HTTP status {_0:?} when loading asset")]
#[error(ignore)]
#[error("Encountered HTTP status {0:?} when loading asset")]
HttpError(u16),
}

Expand Down Expand Up @@ -333,11 +331,11 @@ pub type Writer = dyn AsyncWrite + Unpin + Send + Sync;
pub type PathStream = dyn Stream<Item = PathBuf> + Unpin + Send;

/// Errors that occur while loading assets.
#[derive(Error, Display, Debug, From)]
#[derive(Error, Debug)]
pub enum AssetWriterError {
/// Encountered an I/O error while loading an asset.
#[display("encountered an io error while loading asset: {_0}")]
Io(std::io::Error),
#[error("encountered an io error while loading asset: {0}")]
Io(#[from] std::io::Error),
}

/// Preforms write operations on an asset storage. [`AssetWriter`] exposes a "virtual filesystem"
Expand Down
22 changes: 9 additions & 13 deletions crates/bevy_asset/src/io/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bevy_utils::{
Duration, HashMap,
};
use core::{fmt::Display, hash::Hash};
use derive_more::derive::{Display, Error};
use thiserror::Error;

use super::{ErasedAssetReader, ErasedAssetWriter};

Expand Down Expand Up @@ -629,27 +629,23 @@ impl AssetSources {
}

/// An error returned when an [`AssetSource`] does not exist for a given id.
#[derive(Error, Display, Debug, Clone, PartialEq, Eq)]
#[display("Asset Source '{_0}' does not exist")]
#[error(ignore)]
#[derive(Error, Debug, Clone, PartialEq, Eq)]
#[error("Asset Source '{0}' does not exist")]
pub struct MissingAssetSourceError(AssetSourceId<'static>);

/// An error returned when an [`AssetWriter`](crate::io::AssetWriter) does not exist for a given id.
#[derive(Error, Display, Debug, Clone)]
#[display("Asset Source '{_0}' does not have an AssetWriter.")]
#[error(ignore)]
#[derive(Error, Debug, Clone)]
#[error("Asset Source '{0}' does not have an AssetWriter.")]
pub struct MissingAssetWriterError(AssetSourceId<'static>);

/// An error returned when a processed [`AssetReader`](crate::io::AssetReader) does not exist for a given id.
#[derive(Error, Display, Debug, Clone, PartialEq, Eq)]
#[display("Asset Source '{_0}' does not have a processed AssetReader.")]
#[error(ignore)]
#[derive(Error, Debug, Clone, PartialEq, Eq)]
#[error("Asset Source '{0}' does not have a processed AssetReader.")]
pub struct MissingProcessedAssetReaderError(AssetSourceId<'static>);

/// An error returned when a processed [`AssetWriter`](crate::io::AssetWriter) does not exist for a given id.
#[derive(Error, Display, Debug, Clone)]
#[display("Asset Source '{_0}' does not have a processed AssetWriter.")]
#[error(ignore)]
#[derive(Error, Debug, Clone)]
#[error("Asset Source '{0}' does not have a processed AssetWriter.")]
pub struct MissingProcessedAssetWriterError(AssetSourceId<'static>);

const MISSING_DEFAULT_SOURCE: &str =
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,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 {
Expand Down Expand Up @@ -660,14 +660,14 @@ mod tests {
#[derive(Default)]
pub struct CoolTextLoader;

#[derive(Error, Display, Debug, From)]
#[derive(Error, Debug)]
pub enum CoolTextLoaderError {
#[display("Could not load dependency: {dependency}")]
#[error("Could not load dependency: {dependency}")]
CannotLoadDependency { dependency: AssetPath<'static> },
#[display("A RON error occurred during loading")]
RonSpannedError(ron::error::SpannedError),
#[display("An IO error occurred during loading")]
Io(std::io::Error),
#[error("A RON error occurred during loading")]
RonSpannedError(#[from] ron::error::SpannedError),
#[error("An IO error occurred during loading")]
Io(#[from] std::io::Error),
}

impl AssetLoader for CoolTextLoader {
Expand Down
Loading

0 comments on commit 78d8f4c

Please sign in to comment.