diff --git a/crates/bevy_gltf/Cargo.toml b/crates/bevy_gltf/Cargo.toml index 9b0ef61cbb809..c25bb05778aaa 100644 --- a/crates/bevy_gltf/Cargo.toml +++ b/crates/bevy_gltf/Cargo.toml @@ -54,7 +54,11 @@ gltf = { version = "1.4.0", default-features = false, features = [ "names", "utils", ] } -thiserror = "1.0" +derive_more = { version = "1", default-features = false, features = [ + "error", + "from", + "display", +] } base64 = "0.22.0" percent-encoding = "2.1" serde = { version = "1.0", features = ["derive"] } diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 046c0550a5aae..f63f2fddba674 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -45,6 +45,7 @@ use bevy_utils::{ tracing::{error, info_span, warn}, HashMap, HashSet, }; +use derive_more::derive::{Display, Error, From}; use gltf::{ accessor::Iter, image::Source, @@ -59,7 +60,6 @@ use std::{ io::Error, path::{Path, PathBuf}, }; -use thiserror::Error; #[cfg(feature = "bevy_animation")] use { bevy_animation::{prelude::*, AnimationTarget, AnimationTargetId}, @@ -67,53 +67,59 @@ use { }; /// An error that occurs when loading a glTF file. -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub enum GltfError { /// Unsupported primitive mode. - #[error("unsupported primitive mode")] + #[display("unsupported primitive mode")] UnsupportedPrimitive { /// The primitive mode. mode: Mode, }, /// Invalid glTF file. - #[error("invalid glTF file: {0}")] - Gltf(#[from] gltf::Error), + #[display("invalid glTF file: {_0}")] + Gltf(gltf::Error), /// Binary blob is missing. - #[error("binary blob is missing")] + #[display("binary blob is missing")] MissingBlob, /// Decoding the base64 mesh data failed. - #[error("failed to decode base64 mesh data")] - Base64Decode(#[from] base64::DecodeError), + #[display("failed to decode base64 mesh data")] + Base64Decode(base64::DecodeError), /// Unsupported buffer format. - #[error("unsupported buffer format")] + #[display("unsupported buffer format")] BufferFormatUnsupported, /// Invalid image mime type. - #[error("invalid image mime type: {0}")] + #[display("invalid image mime type: {_0}")] + #[error(ignore)] + #[from(ignore)] InvalidImageMimeType(String), /// Error when loading a texture. Might be due to a disabled image file format feature. - #[error("You may need to add the feature for the file format: {0}")] - ImageError(#[from] TextureError), + #[display("You may need to add the feature for the file format: {_0}")] + ImageError(TextureError), /// Failed to read bytes from an asset path. - #[error("failed to read bytes from an asset path: {0}")] - ReadAssetBytesError(#[from] ReadAssetBytesError), + #[display("failed to read bytes from an asset path: {_0}")] + ReadAssetBytesError(ReadAssetBytesError), /// Failed to load asset from an asset path. - #[error("failed to load asset from an asset path: {0}")] - AssetLoadError(#[from] AssetLoadError), + #[display("failed to load asset from an asset path: {_0}")] + AssetLoadError(AssetLoadError), /// Missing sampler for an animation. - #[error("Missing sampler for animation {0}")] + #[display("Missing sampler for animation {_0}")] + #[error(ignore)] + #[from(ignore)] MissingAnimationSampler(usize), /// Failed to generate tangents. - #[error("failed to generate tangents: {0}")] - GenerateTangentsError(#[from] bevy_render::mesh::GenerateTangentsError), + #[display("failed to generate tangents: {_0}")] + GenerateTangentsError(bevy_render::mesh::GenerateTangentsError), /// Failed to generate morph targets. - #[error("failed to generate morph targets: {0}")] - MorphTarget(#[from] bevy_render::mesh::morph::MorphBuildError), + #[display("failed to generate morph targets: {_0}")] + MorphTarget(bevy_render::mesh::morph::MorphBuildError), /// Circular children in Nodes - #[error("GLTF model must be a tree, found cycle instead at node indices: {0:?}")] + #[display("GLTF model must be a tree, found cycle instead at node indices: {_0:?}")] + #[error(ignore)] + #[from(ignore)] CircularChildren(String), /// Failed to load a file. - #[error("failed to load file: {0}")] - Io(#[from] Error), + #[display("failed to load file: {_0}")] + Io(Error), } /// Loads glTF files with all of their data as their corresponding bevy representations. diff --git a/crates/bevy_gltf/src/vertex_attributes.rs b/crates/bevy_gltf/src/vertex_attributes.rs index d42ecbf397771..c08d072f4c4fd 100644 --- a/crates/bevy_gltf/src/vertex_attributes.rs +++ b/crates/bevy_gltf/src/vertex_attributes.rs @@ -4,11 +4,11 @@ use bevy_render::{ render_resource::VertexFormat, }; use bevy_utils::HashMap; +use derive_more::derive::{Display, Error}; use gltf::{ accessor::{DataType, Dimensions}, mesh::util::{ReadColors, ReadJoints, ReadTexCoords, ReadWeights}, }; -use thiserror::Error; /// Represents whether integer data requires normalization #[derive(Copy, Clone)] @@ -30,11 +30,11 @@ impl Normalization { } /// An error that occurs when accessing buffer data -#[derive(Error, Debug)] +#[derive(Error, Display, Debug)] pub(crate) enum AccessFailed { - #[error("Malformed vertex attribute data")] + #[display("Malformed vertex attribute data")] MalformedData, - #[error("Unsupported vertex attribute format")] + #[display("Unsupported vertex attribute format")] UnsupportedFormat, } @@ -241,13 +241,16 @@ enum ConversionMode { TexCoord, } -#[derive(Error, Debug)] +#[derive(Error, Display, Debug)] +#[error(ignore)] pub(crate) enum ConvertAttributeError { - #[error("Vertex attribute {0} has format {1:?} but expected {3:?} for target attribute {2}")] + #[display( + "Vertex attribute {_0} has format {_1:?} but expected {_3:?} for target attribute {_2}" + )] WrongFormat(String, VertexFormat, String, VertexFormat), - #[error("{0} in accessor {1}")] + #[display("{0} in accessor {_1}")] AccessFailed(AccessFailed, usize), - #[error("Unknown vertex attribute {0}")] + #[display("Unknown vertex attribute {_0}")] UnknownName(String), }