From 80fe269349ba6fbca9e14753fc2a2bf23c3e6718 Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Thu, 10 Oct 2024 01:24:54 +1100 Subject: [PATCH] Remove `thiserror` from `bevy_mesh` (#15768) # Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_mesh` --- crates/bevy_mesh/Cargo.toml | 6 +++++- crates/bevy_mesh/src/conversions.rs | 6 +++--- crates/bevy_mesh/src/index.rs | 20 +++++++++---------- crates/bevy_mesh/src/mikktspace.rs | 17 +++++++++------- crates/bevy_mesh/src/morph.rs | 8 ++++---- .../bevy_mesh/src/primitives/dim3/sphere.rs | 6 +++--- crates/bevy_mesh/src/vertex.rs | 6 +++--- 7 files changed, 38 insertions(+), 31 deletions(-) diff --git a/crates/bevy_mesh/Cargo.toml b/crates/bevy_mesh/Cargo.toml index 1f3d542d67058..21d4fb31fe53d 100644 --- a/crates/bevy_mesh/Cargo.toml +++ b/crates/bevy_mesh/Cargo.toml @@ -27,7 +27,11 @@ bytemuck = { version = "1.5" } wgpu = { version = "22", default-features = false } serde = { version = "1", features = ["derive"] } hexasphere = "15.0" -thiserror = "1.0" +derive_more = { version = "1", default-features = false, features = [ + "error", + "from", + "display", +] } [lints] workspace = true diff --git a/crates/bevy_mesh/src/conversions.rs b/crates/bevy_mesh/src/conversions.rs index f68c2d6f74321..58cb9b42d0d58 100644 --- a/crates/bevy_mesh/src/conversions.rs +++ b/crates/bevy_mesh/src/conversions.rs @@ -26,10 +26,10 @@ use super::VertexAttributeValues; use bevy_math::{IVec2, IVec3, IVec4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec3A, Vec4}; -use thiserror::Error; +use derive_more::derive::{Display, Error}; -#[derive(Debug, Clone, Error)] -#[error("cannot convert VertexAttributeValues::{variant} to {into}")] +#[derive(Debug, Clone, Error, Display)] +#[display("cannot convert VertexAttributeValues::{variant} to {into}")] pub struct FromVertexAttributeError { from: VertexAttributeValues, variant: &'static str, diff --git a/crates/bevy_mesh/src/index.rs b/crates/bevy_mesh/src/index.rs index a6090a19d9beb..5ec5c993a94ea 100644 --- a/crates/bevy_mesh/src/index.rs +++ b/crates/bevy_mesh/src/index.rs @@ -1,6 +1,6 @@ use bevy_reflect::Reflect; use core::iter::FusedIterator; -use thiserror::Error; +use derive_more::derive::{Display, Error}; use wgpu::IndexFormat; /// A disjunction of four iterators. This is necessary to have a well-formed type for the output @@ -33,35 +33,35 @@ where } /// An error that occurred while trying to invert the winding of a [`Mesh`](super::Mesh). -#[derive(Debug, Error)] +#[derive(Debug, Error, Display)] pub enum MeshWindingInvertError { /// This error occurs when you try to invert the winding for a mesh with [`PrimitiveTopology::PointList`](super::PrimitiveTopology::PointList). - #[error("Mesh winding invertation does not work for primitive topology `PointList`")] + #[display("Mesh winding invertation does not work for primitive topology `PointList`")] WrongTopology, /// This error occurs when you try to invert the winding for a mesh with /// * [`PrimitiveTopology::TriangleList`](super::PrimitiveTopology::TriangleList), but the indices are not in chunks of 3. /// * [`PrimitiveTopology::LineList`](super::PrimitiveTopology::LineList), but the indices are not in chunks of 2. - #[error("Indices weren't in chunks according to topology")] + #[display("Indices weren't in chunks according to topology")] AbruptIndicesEnd, } /// An error that occurred while trying to extract a collection of triangles from a [`Mesh`](super::Mesh). -#[derive(Debug, Error)] +#[derive(Debug, Error, Display)] pub enum MeshTrianglesError { - #[error("Source mesh does not have primitive topology TriangleList or TriangleStrip")] + #[display("Source mesh does not have primitive topology TriangleList or TriangleStrip")] WrongTopology, - #[error("Source mesh lacks position data")] + #[display("Source mesh lacks position data")] MissingPositions, - #[error("Source mesh position data is not Float32x3")] + #[display("Source mesh position data is not Float32x3")] PositionsFormat, - #[error("Source mesh lacks face index data")] + #[display("Source mesh lacks face index data")] MissingIndices, - #[error("Face index data references vertices that do not exist")] + #[display("Face index data references vertices that do not exist")] BadIndices, } diff --git a/crates/bevy_mesh/src/mikktspace.rs b/crates/bevy_mesh/src/mikktspace.rs index ab44758fc3a4a..08d8f14c3db9a 100644 --- a/crates/bevy_mesh/src/mikktspace.rs +++ b/crates/bevy_mesh/src/mikktspace.rs @@ -1,6 +1,6 @@ use super::{Indices, Mesh, VertexAttributeValues}; use bevy_math::Vec3; -use thiserror::Error; +use derive_more::derive::{Display, Error}; use wgpu::{PrimitiveTopology, VertexFormat}; struct MikktspaceGeometryHelper<'a> { @@ -53,18 +53,21 @@ impl bevy_mikktspace::Geometry for MikktspaceGeometryHelper<'_> { } } -#[derive(Error, Debug)] +#[derive(Error, Display, Debug)] /// Failed to generate tangents for the mesh. pub enum GenerateTangentsError { - #[error("cannot generate tangents for {0:?}")] + #[display("cannot generate tangents for {_0:?}")] + #[error(ignore)] UnsupportedTopology(PrimitiveTopology), - #[error("missing indices")] + #[display("missing indices")] MissingIndices, - #[error("missing vertex attributes '{0}'")] + #[display("missing vertex attributes '{_0}'")] + #[error(ignore)] MissingVertexAttribute(&'static str), - #[error("the '{0}' vertex attribute should have {1:?} format")] + #[display("the '{_0}' vertex attribute should have {_1:?} format")] + #[error(ignore)] InvalidVertexAttributeFormat(&'static str, VertexFormat), - #[error("mesh not suitable for tangent generation")] + #[display("mesh not suitable for tangent generation")] MikktspaceError, } diff --git a/crates/bevy_mesh/src/morph.rs b/crates/bevy_mesh/src/morph.rs index c1e0be8a5b9bf..a13b5879cf5c4 100644 --- a/crates/bevy_mesh/src/morph.rs +++ b/crates/bevy_mesh/src/morph.rs @@ -6,7 +6,7 @@ use bevy_math::Vec3; use bevy_reflect::prelude::*; use bytemuck::{Pod, Zeroable}; use core::iter; -use thiserror::Error; +use derive_more::derive::{Display, Error}; use wgpu::{Extent3d, TextureDimension, TextureFormat}; const MAX_TEXTURE_WIDTH: u32 = 2048; @@ -17,9 +17,9 @@ const MAX_COMPONENTS: u32 = MAX_TEXTURE_WIDTH * MAX_TEXTURE_WIDTH; /// Max target count available for [morph targets](MorphWeights). pub const MAX_MORPH_WEIGHTS: usize = 64; -#[derive(Error, Clone, Debug)] +#[derive(Error, Display, Clone, Debug)] pub enum MorphBuildError { - #[error( + #[display( "Too many vertexĂ—components in morph target, max is {MAX_COMPONENTS}, \ got {vertex_count}Ă—{component_count} = {}", *vertex_count * *component_count as usize @@ -28,7 +28,7 @@ pub enum MorphBuildError { vertex_count: usize, component_count: u32, }, - #[error( + #[display( "Bevy only supports up to {} morph targets (individual poses), tried to \ create a model with {target_count} morph targets", MAX_MORPH_WEIGHTS diff --git a/crates/bevy_mesh/src/primitives/dim3/sphere.rs b/crates/bevy_mesh/src/primitives/dim3/sphere.rs index ab507d693d192..0a595886b2be5 100644 --- a/crates/bevy_mesh/src/primitives/dim3/sphere.rs +++ b/crates/bevy_mesh/src/primitives/dim3/sphere.rs @@ -2,15 +2,15 @@ use crate::{Indices, Mesh, MeshBuilder, Meshable}; use bevy_asset::RenderAssetUsages; use bevy_math::{ops, primitives::Sphere}; use core::f32::consts::PI; +use derive_more::derive::{Display, Error}; use hexasphere::shapes::IcoSphere; -use thiserror::Error; use wgpu::PrimitiveTopology; /// An error when creating an icosphere [`Mesh`] from a [`SphereMeshBuilder`]. -#[derive(Clone, Copy, Debug, Error)] +#[derive(Clone, Copy, Debug, Error, Display)] pub enum IcosphereError { /// The icosphere has too many vertices. - #[error("Cannot create an icosphere of {subdivisions} subdivisions due to there being too many vertices being generated: {number_of_resulting_points}. (Limited to 65535 vertices or 79 subdivisions)")] + #[display("Cannot create an icosphere of {subdivisions} subdivisions due to there being too many vertices being generated: {number_of_resulting_points}. (Limited to 65535 vertices or 79 subdivisions)")] TooManyVertices { /// The number of subdivisions used. 79 is the largest allowed value for a mesh to be generated. subdivisions: u32, diff --git a/crates/bevy_mesh/src/vertex.rs b/crates/bevy_mesh/src/vertex.rs index 40420ed745fec..a6b52dac7e086 100644 --- a/crates/bevy_mesh/src/vertex.rs +++ b/crates/bevy_mesh/src/vertex.rs @@ -5,7 +5,7 @@ use bevy_math::Vec3; use bevy_utils::HashSet; use bytemuck::cast_slice; use core::hash::{Hash, Hasher}; -use thiserror::Error; +use derive_more::derive::{Display, Error}; use wgpu::{BufferAddress, VertexAttribute, VertexFormat, VertexStepMode}; #[derive(Debug, Clone, Copy)] @@ -108,8 +108,8 @@ impl MeshVertexBufferLayout { } } -#[derive(Error, Debug)] -#[error("Mesh is missing requested attribute: {name} ({id:?}, pipeline type: {pipeline_type:?})")] +#[derive(Error, Display, Debug)] +#[display("Mesh is missing requested attribute: {name} ({id:?}, pipeline type: {pipeline_type:?})")] pub struct MissingVertexAttributeError { pub pipeline_type: Option<&'static str>, id: MeshVertexAttributeId,