Remove thiserror from bevy_gltf (#15772)

# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_gltf`
This commit is contained in:
Zachary Harrold 2024-10-10 01:22:00 +11:00 committed by GitHub
parent c6a2411e90
commit f88c6820f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 33 deletions

View file

@ -54,7 +54,11 @@ gltf = { version = "1.4.0", default-features = false, features = [
"names", "names",
"utils", "utils",
] } ] }
thiserror = "1.0" derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
base64 = "0.22.0" base64 = "0.22.0"
percent-encoding = "2.1" percent-encoding = "2.1"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }

View file

@ -45,6 +45,7 @@ use bevy_utils::{
tracing::{error, info_span, warn}, tracing::{error, info_span, warn},
HashMap, HashSet, HashMap, HashSet,
}; };
use derive_more::derive::{Display, Error, From};
use gltf::{ use gltf::{
accessor::Iter, accessor::Iter,
image::Source, image::Source,
@ -59,7 +60,6 @@ use std::{
io::Error, io::Error,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use thiserror::Error;
#[cfg(feature = "bevy_animation")] #[cfg(feature = "bevy_animation")]
use { use {
bevy_animation::{prelude::*, AnimationTarget, AnimationTargetId}, bevy_animation::{prelude::*, AnimationTarget, AnimationTargetId},
@ -67,53 +67,59 @@ use {
}; };
/// An error that occurs when loading a glTF file. /// An error that occurs when loading a glTF file.
#[derive(Error, Debug)] #[derive(Error, Display, Debug, From)]
pub enum GltfError { pub enum GltfError {
/// Unsupported primitive mode. /// Unsupported primitive mode.
#[error("unsupported primitive mode")] #[display("unsupported primitive mode")]
UnsupportedPrimitive { UnsupportedPrimitive {
/// The primitive mode. /// The primitive mode.
mode: Mode, mode: Mode,
}, },
/// Invalid glTF file. /// Invalid glTF file.
#[error("invalid glTF file: {0}")] #[display("invalid glTF file: {_0}")]
Gltf(#[from] gltf::Error), Gltf(gltf::Error),
/// Binary blob is missing. /// Binary blob is missing.
#[error("binary blob is missing")] #[display("binary blob is missing")]
MissingBlob, MissingBlob,
/// Decoding the base64 mesh data failed. /// Decoding the base64 mesh data failed.
#[error("failed to decode base64 mesh data")] #[display("failed to decode base64 mesh data")]
Base64Decode(#[from] base64::DecodeError), Base64Decode(base64::DecodeError),
/// Unsupported buffer format. /// Unsupported buffer format.
#[error("unsupported buffer format")] #[display("unsupported buffer format")]
BufferFormatUnsupported, BufferFormatUnsupported,
/// Invalid image mime type. /// Invalid image mime type.
#[error("invalid image mime type: {0}")] #[display("invalid image mime type: {_0}")]
#[error(ignore)]
#[from(ignore)]
InvalidImageMimeType(String), InvalidImageMimeType(String),
/// Error when loading a texture. Might be due to a disabled image file format feature. /// 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}")] #[display("You may need to add the feature for the file format: {_0}")]
ImageError(#[from] TextureError), ImageError(TextureError),
/// Failed to read bytes from an asset path. /// Failed to read bytes from an asset path.
#[error("failed to read bytes from an asset path: {0}")] #[display("failed to read bytes from an asset path: {_0}")]
ReadAssetBytesError(#[from] ReadAssetBytesError), ReadAssetBytesError(ReadAssetBytesError),
/// Failed to load asset from an asset path. /// Failed to load asset from an asset path.
#[error("failed to load asset from an asset path: {0}")] #[display("failed to load asset from an asset path: {_0}")]
AssetLoadError(#[from] AssetLoadError), AssetLoadError(AssetLoadError),
/// Missing sampler for an animation. /// Missing sampler for an animation.
#[error("Missing sampler for animation {0}")] #[display("Missing sampler for animation {_0}")]
#[error(ignore)]
#[from(ignore)]
MissingAnimationSampler(usize), MissingAnimationSampler(usize),
/// Failed to generate tangents. /// Failed to generate tangents.
#[error("failed to generate tangents: {0}")] #[display("failed to generate tangents: {_0}")]
GenerateTangentsError(#[from] bevy_render::mesh::GenerateTangentsError), GenerateTangentsError(bevy_render::mesh::GenerateTangentsError),
/// Failed to generate morph targets. /// Failed to generate morph targets.
#[error("failed to generate morph targets: {0}")] #[display("failed to generate morph targets: {_0}")]
MorphTarget(#[from] bevy_render::mesh::morph::MorphBuildError), MorphTarget(bevy_render::mesh::morph::MorphBuildError),
/// Circular children in Nodes /// 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), CircularChildren(String),
/// Failed to load a file. /// Failed to load a file.
#[error("failed to load file: {0}")] #[display("failed to load file: {_0}")]
Io(#[from] Error), Io(Error),
} }
/// Loads glTF files with all of their data as their corresponding bevy representations. /// Loads glTF files with all of their data as their corresponding bevy representations.

View file

@ -4,11 +4,11 @@ use bevy_render::{
render_resource::VertexFormat, render_resource::VertexFormat,
}; };
use bevy_utils::HashMap; use bevy_utils::HashMap;
use derive_more::derive::{Display, Error};
use gltf::{ use gltf::{
accessor::{DataType, Dimensions}, accessor::{DataType, Dimensions},
mesh::util::{ReadColors, ReadJoints, ReadTexCoords, ReadWeights}, mesh::util::{ReadColors, ReadJoints, ReadTexCoords, ReadWeights},
}; };
use thiserror::Error;
/// Represents whether integer data requires normalization /// Represents whether integer data requires normalization
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -30,11 +30,11 @@ impl Normalization {
} }
/// An error that occurs when accessing buffer data /// An error that occurs when accessing buffer data
#[derive(Error, Debug)] #[derive(Error, Display, Debug)]
pub(crate) enum AccessFailed { pub(crate) enum AccessFailed {
#[error("Malformed vertex attribute data")] #[display("Malformed vertex attribute data")]
MalformedData, MalformedData,
#[error("Unsupported vertex attribute format")] #[display("Unsupported vertex attribute format")]
UnsupportedFormat, UnsupportedFormat,
} }
@ -241,13 +241,16 @@ enum ConversionMode {
TexCoord, TexCoord,
} }
#[derive(Error, Debug)] #[derive(Error, Display, Debug)]
#[error(ignore)]
pub(crate) enum ConvertAttributeError { 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), WrongFormat(String, VertexFormat, String, VertexFormat),
#[error("{0} in accessor {1}")] #[display("{0} in accessor {_1}")]
AccessFailed(AccessFailed, usize), AccessFailed(AccessFailed, usize),
#[error("Unknown vertex attribute {0}")] #[display("Unknown vertex attribute {_0}")]
UnknownName(String), UnknownName(String),
} }