Skip to content

Commit b50f2ec

Browse files
Remove thiserror from bevy_scene (#15764)
# Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_scene`
1 parent c9e41ef commit b50f2ec

File tree

4 files changed

+24
-31
lines changed

4 files changed

+24
-31
lines changed

crates/bevy_scene/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ bevy_render = { path = "../bevy_render", version = "0.15.0-dev", optional = true
2929
# other
3030
serde = { version = "1.0", features = ["derive"], optional = true }
3131
uuid = { version = "1.1", features = ["v4"] }
32-
thiserror = "1.0"
32+
derive_more = { version = "1", default-features = false, features = [
33+
"error",
34+
"from",
35+
"display",
36+
] }
3337

3438
[dev-dependencies]
3539
postcard = { version = "1.0", features = ["alloc"] }

crates/bevy_scene/src/components.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use bevy_derive::{Deref, DerefMut};
33
use bevy_ecs::component::Component;
44
use bevy_reflect::Reflect;
55
use bevy_transform::components::Transform;
6+
use derive_more::derive::From;
67

78
#[cfg(feature = "bevy_render")]
89
use bevy_render::view::visibility::Visibility;
@@ -11,26 +12,14 @@ use crate::{DynamicScene, Scene};
1112

1213
/// Adding this component will spawn the scene as a child of that entity.
1314
/// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component.
14-
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)]
15+
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
1516
#[require(Transform)]
1617
#[cfg_attr(feature = "bevy_render", require(Visibility))]
1718
pub struct SceneRoot(pub Handle<Scene>);
1819

19-
impl From<Handle<Scene>> for SceneRoot {
20-
fn from(handle: Handle<Scene>) -> Self {
21-
Self(handle)
22-
}
23-
}
24-
2520
/// Adding this component will spawn the scene as a child of that entity.
2621
/// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component.
27-
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)]
22+
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
2823
#[require(Transform)]
2924
#[cfg_attr(feature = "bevy_render", require(Visibility))]
3025
pub struct DynamicSceneRoot(pub Handle<DynamicScene>);
31-
32-
impl From<Handle<DynamicScene>> for DynamicSceneRoot {
33-
fn from(handle: Handle<DynamicScene>) -> Self {
34-
Self(handle)
35-
}
36-
}

crates/bevy_scene/src/scene_loader.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use bevy_ecs::{
77
world::{FromWorld, World},
88
};
99
use bevy_reflect::TypeRegistryArc;
10+
use derive_more::derive::{Display, Error, From};
1011
#[cfg(feature = "serialize")]
1112
use serde::de::DeserializeSeed;
12-
use thiserror::Error;
1313

1414
/// Asset loader for a Bevy dynamic scene (`.scn` / `.scn.ron`).
1515
///
@@ -30,14 +30,14 @@ impl FromWorld for SceneLoader {
3030

3131
/// Possible errors that can be produced by [`SceneLoader`]
3232
#[non_exhaustive]
33-
#[derive(Debug, Error)]
33+
#[derive(Debug, Error, Display, From)]
3434
pub enum SceneLoaderError {
3535
/// An [IO Error](std::io::Error)
36-
#[error("Error while trying to read the scene file: {0}")]
37-
Io(#[from] std::io::Error),
36+
#[display("Error while trying to read the scene file: {_0}")]
37+
Io(std::io::Error),
3838
/// A [RON Error](ron::error::SpannedError)
39-
#[error("Could not parse RON: {0}")]
40-
RonSpannedError(#[from] ron::error::SpannedError),
39+
#[display("Could not parse RON: {_0}")]
40+
RonSpannedError(ron::error::SpannedError),
4141
}
4242

4343
#[cfg(feature = "serialize")]

crates/bevy_scene/src/scene_spawner.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use bevy_ecs::{
88
world::{Command, Mut, World},
99
};
1010
use bevy_hierarchy::{AddChild, BuildChildren, DespawnRecursiveExt, Parent};
11-
use bevy_utils::{tracing::error, HashMap, HashSet};
12-
use thiserror::Error;
11+
use bevy_utils::{HashMap, HashSet};
12+
use derive_more::derive::{Display, Error};
1313
use uuid::Uuid;
1414

1515
/// Triggered on a scene's parent entity when [`crate::SceneInstance`] becomes ready to use.
@@ -72,22 +72,22 @@ pub struct SceneSpawner {
7272
}
7373

7474
/// Errors that can occur when spawning a scene.
75-
#[derive(Error, Debug)]
75+
#[derive(Error, Display, Debug)]
7676
pub enum SceneSpawnError {
7777
/// Scene contains an unregistered component type.
78-
#[error("scene contains the unregistered component `{type_path}`. consider adding `#[reflect(Component)]` to your type")]
78+
#[display("scene contains the unregistered component `{type_path}`. consider adding `#[reflect(Component)]` to your type")]
7979
UnregisteredComponent {
8080
/// Type of the unregistered component.
8181
type_path: String,
8282
},
8383
/// Scene contains an unregistered resource type.
84-
#[error("scene contains the unregistered resource `{type_path}`. consider adding `#[reflect(Resource)]` to your type")]
84+
#[display("scene contains the unregistered resource `{type_path}`. consider adding `#[reflect(Resource)]` to your type")]
8585
UnregisteredResource {
8686
/// Type of the unregistered resource.
8787
type_path: String,
8888
},
8989
/// Scene contains an unregistered type.
90-
#[error(
90+
#[display(
9191
"scene contains the unregistered type `{std_type_name}`. \
9292
consider reflecting it with `#[derive(Reflect)]` \
9393
and registering the type using `app.register_type::<T>()`"
@@ -97,7 +97,7 @@ pub enum SceneSpawnError {
9797
std_type_name: String,
9898
},
9999
/// Scene contains an unregistered type which has a `TypePath`.
100-
#[error(
100+
#[display(
101101
"scene contains the reflected type `{type_path}` but it was not found in the type registry. \
102102
consider registering the type using `app.register_type::<T>()``"
103103
)]
@@ -106,19 +106,19 @@ pub enum SceneSpawnError {
106106
type_path: String,
107107
},
108108
/// Scene contains a proxy without a represented type.
109-
#[error("scene contains dynamic type `{type_path}` without a represented type. consider changing this using `set_represented_type`.")]
109+
#[display("scene contains dynamic type `{type_path}` without a represented type. consider changing this using `set_represented_type`.")]
110110
NoRepresentedType {
111111
/// The dynamic instance type.
112112
type_path: String,
113113
},
114114
/// Dynamic scene with the given id does not exist.
115-
#[error("scene does not exist")]
115+
#[display("scene does not exist")]
116116
NonExistentScene {
117117
/// Id of the non-existent dynamic scene.
118118
id: AssetId<DynamicScene>,
119119
},
120120
/// Scene with the given id does not exist.
121-
#[error("scene does not exist")]
121+
#[display("scene does not exist")]
122122
NonExistentRealScene {
123123
/// Id of the non-existent scene.
124124
id: AssetId<Scene>,

0 commit comments

Comments
 (0)