Remove thiserror from bevy_image (#15771)

# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_image`
This commit is contained in:
Zachary Harrold 2024-10-10 01:23:53 +11:00 committed by GitHub
parent 9366b95006
commit 1f4adec7df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 47 additions and 34 deletions

View file

@ -52,7 +52,11 @@ bitflags = { version = "2.3", features = ["serde"] }
bytemuck = { version = "1.5" }
wgpu = { version = "22", default-features = false }
serde = { version = "1", features = ["derive"] }
thiserror = "1.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
futures-lite = "2.0.1"
ddsfile = { version = "0.5.2", optional = true }
ktx2 = { version = "0.3.0", optional = true }

View file

@ -1,8 +1,8 @@
use crate::{Image, TextureFormatPixelInfo};
use bevy_asset::{io::Reader, AssetLoader, LoadContext, RenderAssetUsages};
use derive_more::derive::{Display, Error, From};
use image::ImageDecoder;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use wgpu::{Extent3d, TextureDimension, TextureFormat};
/// Loads EXR textures as Texture assets
@ -18,13 +18,11 @@ pub struct ExrTextureLoaderSettings {
/// Possible errors that can be produced by [`ExrTextureLoader`]
#[non_exhaustive]
#[derive(Debug, Error)]
#[derive(Debug, Error, Display, From)]
#[cfg(feature = "exr")]
pub enum ExrTextureLoaderError {
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
ImageError(#[from] image::ImageError),
Io(std::io::Error),
ImageError(image::ImageError),
}
impl AssetLoader for ExrTextureLoader {

View file

@ -1,9 +1,9 @@
use crate::{Image, TextureFormatPixelInfo};
use bevy_asset::RenderAssetUsages;
use bevy_asset::{io::Reader, AssetLoader, LoadContext};
use derive_more::derive::{Display, Error, From};
use image::DynamicImage;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use wgpu::{Extent3d, TextureDimension, TextureFormat};
/// Loads HDR textures as Texture assets
@ -16,12 +16,12 @@ pub struct HdrTextureLoaderSettings {
}
#[non_exhaustive]
#[derive(Debug, Error)]
#[derive(Debug, Error, Display, From)]
pub enum HdrTextureLoaderError {
#[error("Could load texture: {0}")]
Io(#[from] std::io::Error),
#[error("Could not extract image: {0}")]
Image(#[from] image::ImageError),
#[display("Could load texture: {_0}")]
Io(std::io::Error),
#[display("Could not extract image: {_0}")]
Image(image::ImageError),
}
impl AssetLoader for HdrTextureLoader {

View file

@ -11,8 +11,8 @@ use bevy_math::{AspectRatio, UVec2, UVec3, Vec2};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;
use core::hash::Hash;
use derive_more::derive::{Display, Error, From};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use wgpu::{Extent3d, TextureDimension, TextureFormat, TextureViewDescriptor};
pub trait BevyDefault {
fn bevy_default() -> Self;
@ -1535,39 +1535,48 @@ pub enum TranscodeFormat {
}
/// An error that occurs when accessing specific pixels in a texture
#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
pub enum TextureAccessError {
#[error("out of bounds (x: {x}, y: {y}, z: {z})")]
#[display("out of bounds (x: {x}, y: {y}, z: {z})")]
OutOfBounds { x: u32, y: u32, z: u32 },
#[error("unsupported texture format: {0:?}")]
#[display("unsupported texture format: {_0:?}")]
#[error(ignore)]
UnsupportedTextureFormat(TextureFormat),
#[error("attempt to access texture with different dimension")]
#[display("attempt to access texture with different dimension")]
WrongDimension,
}
/// An error that occurs when loading a texture
#[derive(Error, Debug)]
#[derive(Error, Display, Debug, From)]
#[error(ignore)]
pub enum TextureError {
#[error("invalid image mime type: {0}")]
#[display("invalid image mime type: {_0}")]
#[from(ignore)]
InvalidImageMimeType(String),
#[error("invalid image extension: {0}")]
#[display("invalid image extension: {_0}")]
#[from(ignore)]
InvalidImageExtension(String),
#[error("failed to load an image: {0}")]
ImageError(#[from] image::ImageError),
#[error("unsupported texture format: {0}")]
#[display("failed to load an image: {_0}")]
ImageError(image::ImageError),
#[display("unsupported texture format: {_0}")]
#[from(ignore)]
UnsupportedTextureFormat(String),
#[error("supercompression not supported: {0}")]
#[display("supercompression not supported: {_0}")]
#[from(ignore)]
SuperCompressionNotSupported(String),
#[error("failed to load an image: {0}")]
#[display("failed to load an image: {_0}")]
#[from(ignore)]
SuperDecompressionError(String),
#[error("invalid data: {0}")]
#[display("invalid data: {_0}")]
#[from(ignore)]
InvalidData(String),
#[error("transcode error: {0}")]
#[display("transcode error: {_0}")]
#[from(ignore)]
TranscodeError(String),
#[error("format requires transcoding: {0:?}")]
#[display("format requires transcoding: {_0:?}")]
FormatRequiresTranscodingError(TranscodeFormat),
/// Only cubemaps with six faces are supported.
#[error("only cubemaps with six faces are supported")]
#[display("only cubemaps with six faces are supported")]
IncompleteCubemap,
}

View file

@ -1,7 +1,7 @@
use crate::{Image, TextureFormatPixelInfo};
use bevy_asset::RenderAssetUsages;
use derive_more::derive::{Display, Error};
use image::{DynamicImage, ImageBuffer};
use thiserror::Error;
use wgpu::{Extent3d, TextureDimension, TextureFormat};
impl Image {
@ -204,14 +204,16 @@ impl Image {
/// Errors that occur while converting an [`Image`] into a [`DynamicImage`]
#[non_exhaustive]
#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
pub enum IntoDynamicImageError {
/// Conversion into dynamic image not supported for source format.
#[error("Conversion into dynamic image not supported for {0:?}.")]
#[display("Conversion into dynamic image not supported for {_0:?}.")]
#[error(ignore)]
UnsupportedFormat(TextureFormat),
/// Encountered an unknown error during conversion.
#[error("Failed to convert into {0:?}.")]
#[display("Failed to convert into {_0:?}.")]
#[error(ignore)]
UnknownConversionError(TextureFormat),
}