Remove thiserror from bevy_scene (#15764)

# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_scene`
This commit is contained in:
Zachary Harrold 2024-10-10 01:29:10 +11:00 committed by GitHub
parent c9e41ef552
commit b50f2ec334
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 31 deletions

View file

@ -29,7 +29,11 @@ bevy_render = { path = "../bevy_render", version = "0.15.0-dev", optional = true
# other # other
serde = { version = "1.0", features = ["derive"], optional = true } serde = { version = "1.0", features = ["derive"], optional = true }
uuid = { version = "1.1", features = ["v4"] } uuid = { version = "1.1", features = ["v4"] }
thiserror = "1.0" derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
[dev-dependencies] [dev-dependencies]
postcard = { version = "1.0", features = ["alloc"] } postcard = { version = "1.0", features = ["alloc"] }

View file

@ -3,6 +3,7 @@ use bevy_derive::{Deref, DerefMut};
use bevy_ecs::component::Component; use bevy_ecs::component::Component;
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
use bevy_transform::components::Transform; use bevy_transform::components::Transform;
use derive_more::derive::From;
#[cfg(feature = "bevy_render")] #[cfg(feature = "bevy_render")]
use bevy_render::view::visibility::Visibility; use bevy_render::view::visibility::Visibility;
@ -11,26 +12,14 @@ use crate::{DynamicScene, Scene};
/// Adding this component will spawn the scene as a child of that entity. /// Adding this component will spawn the scene as a child of that entity.
/// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component. /// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component.
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
#[require(Transform)] #[require(Transform)]
#[cfg_attr(feature = "bevy_render", require(Visibility))] #[cfg_attr(feature = "bevy_render", require(Visibility))]
pub struct SceneRoot(pub Handle<Scene>); pub struct SceneRoot(pub Handle<Scene>);
impl From<Handle<Scene>> for SceneRoot {
fn from(handle: Handle<Scene>) -> Self {
Self(handle)
}
}
/// Adding this component will spawn the scene as a child of that entity. /// Adding this component will spawn the scene as a child of that entity.
/// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component. /// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component.
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
#[require(Transform)] #[require(Transform)]
#[cfg_attr(feature = "bevy_render", require(Visibility))] #[cfg_attr(feature = "bevy_render", require(Visibility))]
pub struct DynamicSceneRoot(pub Handle<DynamicScene>); pub struct DynamicSceneRoot(pub Handle<DynamicScene>);
impl From<Handle<DynamicScene>> for DynamicSceneRoot {
fn from(handle: Handle<DynamicScene>) -> Self {
Self(handle)
}
}

View file

@ -7,9 +7,9 @@ use bevy_ecs::{
world::{FromWorld, World}, world::{FromWorld, World},
}; };
use bevy_reflect::TypeRegistryArc; use bevy_reflect::TypeRegistryArc;
use derive_more::derive::{Display, Error, From};
#[cfg(feature = "serialize")] #[cfg(feature = "serialize")]
use serde::de::DeserializeSeed; use serde::de::DeserializeSeed;
use thiserror::Error;
/// Asset loader for a Bevy dynamic scene (`.scn` / `.scn.ron`). /// Asset loader for a Bevy dynamic scene (`.scn` / `.scn.ron`).
/// ///
@ -30,14 +30,14 @@ impl FromWorld for SceneLoader {
/// Possible errors that can be produced by [`SceneLoader`] /// Possible errors that can be produced by [`SceneLoader`]
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Error)] #[derive(Debug, Error, Display, From)]
pub enum SceneLoaderError { pub enum SceneLoaderError {
/// An [IO Error](std::io::Error) /// An [IO Error](std::io::Error)
#[error("Error while trying to read the scene file: {0}")] #[display("Error while trying to read the scene file: {_0}")]
Io(#[from] std::io::Error), Io(std::io::Error),
/// A [RON Error](ron::error::SpannedError) /// A [RON Error](ron::error::SpannedError)
#[error("Could not parse RON: {0}")] #[display("Could not parse RON: {_0}")]
RonSpannedError(#[from] ron::error::SpannedError), RonSpannedError(ron::error::SpannedError),
} }
#[cfg(feature = "serialize")] #[cfg(feature = "serialize")]

View file

@ -8,8 +8,8 @@ use bevy_ecs::{
world::{Command, Mut, World}, world::{Command, Mut, World},
}; };
use bevy_hierarchy::{AddChild, BuildChildren, DespawnRecursiveExt, Parent}; use bevy_hierarchy::{AddChild, BuildChildren, DespawnRecursiveExt, Parent};
use bevy_utils::{tracing::error, HashMap, HashSet}; use bevy_utils::{HashMap, HashSet};
use thiserror::Error; use derive_more::derive::{Display, Error};
use uuid::Uuid; use uuid::Uuid;
/// Triggered on a scene's parent entity when [`crate::SceneInstance`] becomes ready to use. /// Triggered on a scene's parent entity when [`crate::SceneInstance`] becomes ready to use.
@ -72,22 +72,22 @@ pub struct SceneSpawner {
} }
/// Errors that can occur when spawning a scene. /// Errors that can occur when spawning a scene.
#[derive(Error, Debug)] #[derive(Error, Display, Debug)]
pub enum SceneSpawnError { pub enum SceneSpawnError {
/// Scene contains an unregistered component type. /// Scene contains an unregistered component type.
#[error("scene contains the unregistered component `{type_path}`. consider adding `#[reflect(Component)]` to your type")] #[display("scene contains the unregistered component `{type_path}`. consider adding `#[reflect(Component)]` to your type")]
UnregisteredComponent { UnregisteredComponent {
/// Type of the unregistered component. /// Type of the unregistered component.
type_path: String, type_path: String,
}, },
/// Scene contains an unregistered resource type. /// Scene contains an unregistered resource type.
#[error("scene contains the unregistered resource `{type_path}`. consider adding `#[reflect(Resource)]` to your type")] #[display("scene contains the unregistered resource `{type_path}`. consider adding `#[reflect(Resource)]` to your type")]
UnregisteredResource { UnregisteredResource {
/// Type of the unregistered resource. /// Type of the unregistered resource.
type_path: String, type_path: String,
}, },
/// Scene contains an unregistered type. /// Scene contains an unregistered type.
#[error( #[display(
"scene contains the unregistered type `{std_type_name}`. \ "scene contains the unregistered type `{std_type_name}`. \
consider reflecting it with `#[derive(Reflect)]` \ consider reflecting it with `#[derive(Reflect)]` \
and registering the type using `app.register_type::<T>()`" and registering the type using `app.register_type::<T>()`"
@ -97,7 +97,7 @@ pub enum SceneSpawnError {
std_type_name: String, std_type_name: String,
}, },
/// Scene contains an unregistered type which has a `TypePath`. /// Scene contains an unregistered type which has a `TypePath`.
#[error( #[display(
"scene contains the reflected type `{type_path}` but it was not found in the type registry. \ "scene contains the reflected type `{type_path}` but it was not found in the type registry. \
consider registering the type using `app.register_type::<T>()``" consider registering the type using `app.register_type::<T>()``"
)] )]
@ -106,19 +106,19 @@ pub enum SceneSpawnError {
type_path: String, type_path: String,
}, },
/// Scene contains a proxy without a represented type. /// Scene contains a proxy without a represented type.
#[error("scene contains dynamic type `{type_path}` without a represented type. consider changing this using `set_represented_type`.")] #[display("scene contains dynamic type `{type_path}` without a represented type. consider changing this using `set_represented_type`.")]
NoRepresentedType { NoRepresentedType {
/// The dynamic instance type. /// The dynamic instance type.
type_path: String, type_path: String,
}, },
/// Dynamic scene with the given id does not exist. /// Dynamic scene with the given id does not exist.
#[error("scene does not exist")] #[display("scene does not exist")]
NonExistentScene { NonExistentScene {
/// Id of the non-existent dynamic scene. /// Id of the non-existent dynamic scene.
id: AssetId<DynamicScene>, id: AssetId<DynamicScene>,
}, },
/// Scene with the given id does not exist. /// Scene with the given id does not exist.
#[error("scene does not exist")] #[display("scene does not exist")]
NonExistentRealScene { NonExistentRealScene {
/// Id of the non-existent scene. /// Id of the non-existent scene.
id: AssetId<Scene>, id: AssetId<Scene>,