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_scene #15764

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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
6 changes: 5 additions & 1 deletion crates/bevy_scene/Cargo.toml
Original file line number Diff line number Diff line change
@@ -29,7 +29,11 @@ bevy_render = { path = "../bevy_render", version = "0.15.0-dev", optional = true
# other
serde = { version = "1.0", features = ["derive"], optional = true }
uuid = { version = "1.1", features = ["v4"] }
thiserror = "1.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }

[dev-dependencies]
postcard = { version = "1.0", features = ["alloc"] }
17 changes: 3 additions & 14 deletions crates/bevy_scene/src/components.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ use bevy_derive::{Deref, DerefMut};
use bevy_ecs::component::Component;
use bevy_reflect::Reflect;
use bevy_transform::components::Transform;
use derive_more::derive::From;

#[cfg(feature = "bevy_render")]
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.
/// 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)]
#[cfg_attr(feature = "bevy_render", require(Visibility))]
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.
/// 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)]
#[cfg_attr(feature = "bevy_render", require(Visibility))]
pub struct DynamicSceneRoot(pub Handle<DynamicScene>);

impl From<Handle<DynamicScene>> for DynamicSceneRoot {
fn from(handle: Handle<DynamicScene>) -> Self {
Self(handle)
}
}
12 changes: 6 additions & 6 deletions crates/bevy_scene/src/scene_loader.rs
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ use bevy_ecs::{
world::{FromWorld, World},
};
use bevy_reflect::TypeRegistryArc;
use derive_more::derive::{Display, Error, From};
#[cfg(feature = "serialize")]
use serde::de::DeserializeSeed;
use thiserror::Error;

/// 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`]
#[non_exhaustive]
#[derive(Debug, Error)]
#[derive(Debug, Error, Display, From)]
pub enum SceneLoaderError {
/// An [IO Error](std::io::Error)
#[error("Error while trying to read the scene file: {0}")]
Io(#[from] std::io::Error),
#[display("Error while trying to read the scene file: {_0}")]
Io(std::io::Error),
/// A [RON Error](ron::error::SpannedError)
#[error("Could not parse RON: {0}")]
RonSpannedError(#[from] ron::error::SpannedError),
#[display("Could not parse RON: {_0}")]
RonSpannedError(ron::error::SpannedError),
}

#[cfg(feature = "serialize")]
20 changes: 10 additions & 10 deletions crates/bevy_scene/src/scene_spawner.rs
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ use bevy_ecs::{
world::{Command, Mut, World},
};
use bevy_hierarchy::{AddChild, BuildChildren, DespawnRecursiveExt, Parent};
use bevy_utils::{tracing::error, HashMap, HashSet};
use thiserror::Error;
use bevy_utils::{HashMap, HashSet};
use derive_more::derive::{Display, Error};
use uuid::Uuid;

/// 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.
#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
pub enum SceneSpawnError {
/// 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 {
/// Type of the unregistered component.
type_path: String,
},
/// 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 {
/// Type of the unregistered resource.
type_path: String,
},
/// Scene contains an unregistered type.
#[error(
#[display(
"scene contains the unregistered type `{std_type_name}`. \
consider reflecting it with `#[derive(Reflect)]` \
and registering the type using `app.register_type::<T>()`"
@@ -97,7 +97,7 @@ pub enum SceneSpawnError {
std_type_name: String,
},
/// 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. \
consider registering the type using `app.register_type::<T>()``"
)]
@@ -106,19 +106,19 @@ pub enum SceneSpawnError {
type_path: String,
},
/// 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 {
/// The dynamic instance type.
type_path: String,
},
/// Dynamic scene with the given id does not exist.
#[error("scene does not exist")]
#[display("scene does not exist")]
NonExistentScene {
/// Id of the non-existent dynamic scene.
id: AssetId<DynamicScene>,
},
/// Scene with the given id does not exist.
#[error("scene does not exist")]
#[display("scene does not exist")]
NonExistentRealScene {
/// Id of the non-existent scene.
id: AssetId<Scene>,