Skip to content

Commit

Permalink
Remove thiserror from bevy_image (#15771)
Browse files Browse the repository at this point in the history
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_image`
  • Loading branch information
bushrat011899 authored Oct 9, 2024
1 parent 9366b95 commit 1f4adec
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
6 changes: 5 additions & 1 deletion crates/bevy_image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 4 additions & 6 deletions crates/bevy_image/src/exr_texture_loader.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_image/src/hdr_texture_loader.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down
43 changes: 26 additions & 17 deletions crates/bevy_image/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}

Expand Down
10 changes: 6 additions & 4 deletions crates/bevy_image/src/image_texture_conversion.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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),
}

Expand Down

0 comments on commit 1f4adec

Please sign in to comment.