Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove thiserror from bevy_ecs #15774

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ concurrent-queue = "2.4.0"
disqualified = "1.0"
fixedbitset = "0.5"
serde = { version = "1", optional = true, default-features = false }
thiserror = "1.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
"into",
"as_ref",
] }
nonmax = "0.5"
arrayvec = { version = "0.7.4", optional = true }
smallvec = "1"
Expand Down
12 changes: 8 additions & 4 deletions crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use core::{
marker::PhantomData,
mem::needs_drop,
};
use thiserror::Error;
use derive_more::derive::{Display, Error};

/// A data type that can be used to store data for an [entity].
///
Expand Down Expand Up @@ -1623,14 +1623,18 @@ impl<T: Component> FromWorld for InitComponentId<T> {
}

/// An error returned when the registration of a required component fails.
#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
#[non_exhaustive]
pub enum RequiredComponentsError {
/// The component is already a directly required component for the requiree.
#[error("Component {0:?} already directly requires component {1:?}")]
#[display("Component {0:?} already directly requires component {_1:?}")]
#[error(ignore)]
DuplicateRegistration(ComponentId, ComponentId),
/// An archetype with the component that requires other components already exists
#[error("An archetype with the component {0:?} that requires other components already exists")]
#[display(
"An archetype with the component {_0:?} that requires other components already exists"
)]
#[error(ignore)]
ArchetypeExists(ComponentId),
}

Expand Down
9 changes: 2 additions & 7 deletions crates/bevy_ecs/src/query/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::component::ComponentId;
use crate::storage::SparseSetIndex;
use crate::world::World;
use core::{fmt, fmt::Debug, marker::PhantomData};
use derive_more::derive::From;
use fixedbitset::FixedBitSet;

/// A wrapper struct to make Debug representations of [`FixedBitSet`] easier
Expand Down Expand Up @@ -856,7 +857,7 @@ impl<T: SparseSetIndex> From<FilteredAccess<T>> for FilteredAccessSet<T> {
}

/// Records how two accesses conflict with each other
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, From)]
pub enum AccessConflicts {
/// Conflict is for all indices
All,
Expand Down Expand Up @@ -908,12 +909,6 @@ impl AccessConflicts {
}
}

impl From<FixedBitSet> for AccessConflicts {
fn from(value: FixedBitSet) -> Self {
Self::Individual(value)
}
}

impl<T: SparseSetIndex> From<Vec<T>> for AccessConflicts {
fn from(value: Vec<T>) -> Self {
Self::Individual(value.iter().map(T::sparse_set_index).collect())
Expand Down
10 changes: 6 additions & 4 deletions crates/bevy_ecs/src/query/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use thiserror::Error;
use derive_more::derive::{Display, Error};

use crate::{entity::Entity, world::unsafe_world_cell::UnsafeWorldCell};

Expand Down Expand Up @@ -90,13 +90,15 @@ impl<'w> Eq for QueryEntityError<'w> {}

/// An error that occurs when evaluating a [`Query`](crate::system::Query) or [`QueryState`](crate::query::QueryState) as a single expected result via
/// [`get_single`](crate::system::Query::get_single) or [`get_single_mut`](crate::system::Query::get_single_mut).
#[derive(Debug, Error)]
#[derive(Debug, Error, Display)]
pub enum QuerySingleError {
/// No entity fits the query.
#[error("No entities fit the query {0}")]
#[display("No entities fit the query {_0}")]
#[error(ignore)]
NoEntities(&'static str),
/// Multiple entities fit the query.
#[error("Multiple entities fit the query {0}")]
#[display("Multiple entities fit the query {_0}")]
#[error(ignore)]
MultipleEntities(&'static str),
}

Expand Down
10 changes: 3 additions & 7 deletions crates/bevy_ecs/src/removal_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::{
world::{unsafe_world_cell::UnsafeWorldCell, World},
};

use derive_more::derive::Into;

use core::{
fmt::Debug,
iter,
Expand All @@ -21,15 +23,9 @@ use core::{

/// Wrapper around [`Entity`] for [`RemovedComponents`].
/// Internally, `RemovedComponents` uses these as an `Events<RemovedComponentEntity>`.
#[derive(Event, Debug, Clone)]
#[derive(Event, Debug, Clone, Into)]
pub struct RemovedComponentEntity(Entity);

impl From<RemovedComponentEntity> for Entity {
fn from(value: RemovedComponentEntity) -> Self {
value.0
}
}

/// Wrapper around a [`EventCursor<RemovedComponentEntity>`] so that we
/// can differentiate events between components.
#[derive(Debug)]
Expand Down
29 changes: 15 additions & 14 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use bevy_utils::{
tracing::{error, info, warn},
HashMap, HashSet,
};
use derive_more::derive::{Display, Error};
use disqualified::ShortName;
use fixedbitset::FixedBitSet;
use petgraph::{algo::TarjanScc, prelude::*};
use thiserror::Error;

use crate::{
self as bevy_ecs,
Expand Down Expand Up @@ -1934,42 +1934,43 @@ impl ScheduleGraph {
}

/// Category of errors encountered during schedule construction.
#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
#[error(ignore)]
#[non_exhaustive]
pub enum ScheduleBuildError {
/// A system set contains itself.
#[error("System set `{0}` contains itself.")]
#[display("System set `{_0}` contains itself.")]
HierarchyLoop(String),
/// The hierarchy of system sets contains a cycle.
#[error("System set hierarchy contains cycle(s).\n{0}")]
#[display("System set hierarchy contains cycle(s).\n{_0}")]
HierarchyCycle(String),
/// The hierarchy of system sets contains redundant edges.
///
/// This error is disabled by default, but can be opted-in using [`ScheduleBuildSettings`].
#[error("System set hierarchy contains redundant edges.\n{0}")]
#[display("System set hierarchy contains redundant edges.\n{_0}")]
HierarchyRedundancy(String),
/// A system (set) has been told to run before itself.
#[error("System set `{0}` depends on itself.")]
#[display("System set `{_0}` depends on itself.")]
DependencyLoop(String),
/// The dependency graph contains a cycle.
#[error("System dependencies contain cycle(s).\n{0}")]
#[display("System dependencies contain cycle(s).\n{_0}")]
DependencyCycle(String),
/// Tried to order a system (set) relative to a system set it belongs to.
#[error("`{0}` and `{1}` have both `in_set` and `before`-`after` relationships (these might be transitive). This combination is unsolvable as a system cannot run before or after a set it belongs to.")]
#[display("`{0}` and `{_1}` have both `in_set` and `before`-`after` relationships (these might be transitive). This combination is unsolvable as a system cannot run before or after a set it belongs to.")]
CrossDependency(String, String),
/// Tried to order system sets that share systems.
#[error("`{0}` and `{1}` have a `before`-`after` relationship (which may be transitive) but share systems.")]
#[display("`{0}` and `{_1}` have a `before`-`after` relationship (which may be transitive) but share systems.")]
SetsHaveOrderButIntersect(String, String),
/// Tried to order a system (set) relative to all instances of some system function.
#[error("Tried to order against `{0}` in a schedule that has more than one `{0}` instance. `{0}` is a `SystemTypeSet` and cannot be used for ordering if ambiguous. Use a different set without this restriction.")]
#[display("Tried to order against `{0}` in a schedule that has more than one `{0}` instance. `{_0}` is a `SystemTypeSet` and cannot be used for ordering if ambiguous. Use a different set without this restriction.")]
SystemTypeSetAmbiguity(String),
/// Systems with conflicting access have indeterminate run order.
///
/// This error is disabled by default, but can be opted-in using [`ScheduleBuildSettings`].
#[error("Systems with conflicting access have indeterminate run order.\n{0}")]
#[display("Systems with conflicting access have indeterminate run order.\n{_0}")]
Ambiguity(String),
/// Tried to run a schedule before all of its systems have been initialized.
#[error("Systems in schedule have not been initialized.")]
#[display("Systems in schedule have not been initialized.")]
Uninitialized,
}

Expand Down Expand Up @@ -2040,8 +2041,8 @@ impl ScheduleBuildSettings {

/// Error to denote that [`Schedule::initialize`] or [`Schedule::run`] has not yet been called for
/// this schedule.
#[derive(Error, Debug)]
#[error("executable schedule has not been built")]
#[derive(Error, Display, Debug)]
#[display("executable schedule has not been built")]
pub struct ScheduleNotInitialized;

#[cfg(test)]
Expand Down
11 changes: 7 additions & 4 deletions crates/bevy_ecs/src/schedule/stepping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use crate::{
system::{IntoSystem, ResMut, Resource},
};
use bevy_utils::{
tracing::{error, info, warn},
tracing::{info, warn},
TypeIdMap,
};
use thiserror::Error;
use derive_more::derive::{Display, Error};

#[cfg(not(feature = "bevy_debug_stepping"))]
use bevy_utils::tracing::error;

#[cfg(test)]
use bevy_utils::tracing::debug;
Expand Down Expand Up @@ -87,8 +90,8 @@ enum Update {
ClearBehavior(InternedScheduleLabel, SystemIdentifier),
}

#[derive(Error, Debug)]
#[error("not available until all configured schedules have been run; try again next frame")]
#[derive(Error, Display, Debug)]
#[display("not available until all configured schedules have been run; try again next frame")]
pub struct NotReady;

#[derive(Resource, Default)]
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_ecs/src/system/system.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_utils::tracing::warn;
use core::fmt::Debug;
use thiserror::Error;
use derive_more::derive::{Display, Error};

use crate::{
archetype::ArchetypeComponentId,
Expand Down Expand Up @@ -357,12 +357,13 @@ impl RunSystemOnce for &mut World {
}

/// Running system failed.
#[derive(Error)]
#[derive(Error, Display)]
pub enum RunSystemError {
/// System could not be run due to parameters that failed validation.
///
/// This can occur because the data required by the system was not present in the world.
#[error("The data required by the system {0:?} was not found in the world and the system did not run due to failed parameter validation.")]
#[display("The data required by the system {_0:?} was not found in the world and the system did not run due to failed parameter validation.")]
#[error(ignore)]
InvalidParams(Cow<'static, str>),
}

Expand Down
23 changes: 3 additions & 20 deletions crates/bevy_ecs/src/system/system_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
};
use alloc::borrow::Cow;
use core::ops::Deref;
use derive_more::derive::{AsRef, Display, Into};

/// [`SystemParam`] that returns the name of the system which it is used in.
///
Expand Down Expand Up @@ -33,7 +34,8 @@ use core::ops::Deref;
/// logger.log("Hello");
/// }
/// ```
#[derive(Debug)]
#[derive(Debug, Into, Display, AsRef)]
#[as_ref(str)]
pub struct SystemName<'s>(&'s str);

impl<'s> SystemName<'s> {
Expand All @@ -50,25 +52,6 @@ impl<'s> Deref for SystemName<'s> {
}
}

impl<'s> AsRef<str> for SystemName<'s> {
fn as_ref(&self) -> &str {
self.name()
}
}

impl<'s> From<SystemName<'s>> for &'s str {
fn from(name: SystemName<'s>) -> &'s str {
name.0
}
}

impl<'s> core::fmt::Display for SystemName<'s> {
#[inline(always)]
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.name(), f)
}
}

// SAFETY: no component value access
unsafe impl SystemParam for SystemName<'_> {
type State = Cow<'static, str>;
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_ecs/src/system/system_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bevy_ecs_macros::{Component, Resource};
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use core::marker::PhantomData;
use thiserror::Error;
use derive_more::derive::{Display, Error};

/// A small wrapper for [`BoxedSystem`] that also keeps track whether or not the system has been initialized.
#[derive(Component)]
Expand Down Expand Up @@ -587,28 +587,28 @@ where
}

/// An operation with stored systems failed.
#[derive(Error)]
#[derive(Error, Display)]
pub enum RegisteredSystemError<I: SystemInput = (), O = ()> {
/// A system was run by id, but no system with that id was found.
///
/// Did you forget to register it?
#[error("System {0:?} was not registered")]
#[display("System {_0:?} was not registered")]
SystemIdNotRegistered(SystemId<I, O>),
/// A cached system was removed by value, but no system with its type was found.
///
/// Did you forget to register it?
#[error("Cached system was not found")]
#[display("Cached system was not found")]
SystemNotCached,
/// A system tried to run itself recursively.
#[error("System {0:?} tried to run itself recursively")]
#[display("System {_0:?} tried to run itself recursively")]
Recursive(SystemId<I, O>),
/// A system tried to remove itself.
#[error("System {0:?} tried to remove itself")]
#[display("System {_0:?} tried to remove itself")]
SelfRemove(SystemId<I, O>),
/// System could not be run due to parameters that failed validation.
///
/// This can occur because the data required by the system was not present in the world.
#[error("The data required by the system {0:?} was not found in the world and the system did not run due to failed parameter validation.")]
#[display("The data required by the system {_0:?} was not found in the world and the system did not run due to failed parameter validation.")]
InvalidParams(SystemId<I, O>),
}

Expand Down
12 changes: 8 additions & 4 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
use bevy_ptr::{OwningPtr, Ptr};
use bevy_utils::{HashMap, HashSet};
use core::{any::TypeId, marker::PhantomData, mem::MaybeUninit};
use thiserror::Error;
use derive_more::derive::{Display, Error};

use super::{unsafe_world_cell::UnsafeEntityCell, Ref, ON_REMOVE, ON_REPLACE};

Expand Down Expand Up @@ -2774,12 +2774,16 @@ impl<'a> From<&'a mut EntityWorldMut<'_>> for FilteredEntityMut<'a> {
}
}

#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
pub enum TryFromFilteredError {
#[error("Conversion failed, filtered entity ref does not have read access to all components")]
#[display(
"Conversion failed, filtered entity ref does not have read access to all components"
)]
MissingReadAllAccess,

#[error("Conversion failed, filtered entity ref does not have write access to all components")]
#[display(
"Conversion failed, filtered entity ref does not have write access to all components"
)]
MissingWriteAllAccess,
}

Expand Down
Loading
Loading