Remove thiserror from bevy_render (#15765)

# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_render`
This commit is contained in:
Zachary Harrold 2024-10-10 01:26:28 +11:00 committed by GitHub
parent 3cc1527e9e
commit 8718adc74f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 118 additions and 183 deletions

View File

@ -78,7 +78,11 @@ naga = { version = "22", features = ["wgsl-in"] }
serde = { version = "1", features = ["derive"] }
bytemuck = { version = "1.5", features = ["derive", "must_cast"] }
downcast-rs = "1.2.0"
thiserror = "1.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
futures-lite = "2.0.1"
ktx2 = { version = "0.3.0", optional = true }
# For transcoding of UASTC/ETC1S universal formats, and for .basis file support

View File

@ -37,6 +37,7 @@ use bevy_window::{
WindowScaleFactorChanged,
};
use core::ops::Range;
use derive_more::derive::From;
use wgpu::{BlendState, TextureFormat, TextureUsages};
use super::{ClearColorConfig, Projection};
@ -710,7 +711,7 @@ impl CameraRenderGraph {
/// The "target" that a [`Camera`] will render to. For example, this could be a [`Window`]
/// swapchain or an [`Image`].
#[derive(Debug, Clone, Reflect)]
#[derive(Debug, Clone, Reflect, From)]
pub enum RenderTarget {
/// Window to which the camera's view is rendered.
Window(WindowRef),
@ -727,16 +728,10 @@ impl Default for RenderTarget {
}
}
impl From<Handle<Image>> for RenderTarget {
fn from(handle: Handle<Image>) -> Self {
Self::Image(handle)
}
}
/// Normalized version of the render target.
///
/// Once we have this we shouldn't need to resolve it down anymore.
#[derive(Debug, Clone, Reflect, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Debug, Clone, Reflect, PartialEq, Eq, Hash, PartialOrd, Ord, From)]
pub enum NormalizedRenderTarget {
/// Window to which the camera's view is rendered.
Window(NormalizedWindowRef),

View File

@ -3,10 +3,11 @@ use bevy_color::Color;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*;
use bevy_reflect::prelude::*;
use derive_more::derive::From;
use serde::{Deserialize, Serialize};
/// For a camera, specifies the color used to clear the viewport before rendering.
#[derive(Reflect, Serialize, Deserialize, Copy, Clone, Debug, Default)]
#[derive(Reflect, Serialize, Deserialize, Copy, Clone, Debug, Default, From)]
#[reflect(Serialize, Deserialize, Default)]
pub enum ClearColorConfig {
/// The clear color is taken from the world's [`ClearColor`] resource.
@ -20,12 +21,6 @@ pub enum ClearColorConfig {
None,
}
impl From<Color> for ClearColorConfig {
fn from(color: Color) -> Self {
Self::Custom(color)
}
}
/// A [`Resource`] that stores the color that is used to clear the screen between frames.
///
/// This color appears as the "background" color for simple apps,

View File

@ -11,6 +11,7 @@ use bevy_reflect::{
std_traits::ReflectDefault, GetTypeRegistration, Reflect, ReflectDeserialize, ReflectSerialize,
};
use bevy_transform::{components::GlobalTransform, TransformSystem};
use derive_more::derive::From;
use serde::{Deserialize, Serialize};
/// Adds [`Camera`](crate::camera::Camera) driver systems for a given projection type.
@ -98,25 +99,13 @@ pub trait CameraProjection {
}
/// A configurable [`CameraProjection`] that can select its projection type at runtime.
#[derive(Component, Debug, Clone, Reflect)]
#[derive(Component, Debug, Clone, Reflect, From)]
#[reflect(Component, Default, Debug)]
pub enum Projection {
Perspective(PerspectiveProjection),
Orthographic(OrthographicProjection),
}
impl From<PerspectiveProjection> for Projection {
fn from(p: PerspectiveProjection) -> Self {
Self::Perspective(p)
}
}
impl From<OrthographicProjection> for Projection {
fn from(p: OrthographicProjection) -> Self {
Self::Orthographic(p)
}
}
impl CameraProjection for Projection {
fn get_clip_from_view(&self) -> Mat4 {
match self {

View File

@ -4,6 +4,7 @@ use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_transform::components::Transform;
use derive_more::derive::From;
/// A component for rendering 2D meshes, typically with a [`MeshMaterial2d`] using a [`ColorMaterial`].
///
@ -35,17 +36,11 @@ use bevy_transform::components::Transform;
/// ));
/// }
/// ```
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)]
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
#[reflect(Component, Default)]
#[require(Transform, Visibility)]
pub struct Mesh2d(pub Handle<Mesh>);
impl From<Handle<Mesh>> for Mesh2d {
fn from(handle: Handle<Mesh>) -> Self {
Self(handle)
}
}
impl From<Mesh2d> for AssetId<Mesh> {
fn from(mesh: Mesh2d) -> Self {
mesh.id()
@ -91,17 +86,11 @@ impl From<&Mesh2d> for AssetId<Mesh> {
/// ));
/// }
/// ```
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)]
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
#[reflect(Component, Default)]
#[require(Transform, Visibility)]
pub struct Mesh3d(pub Handle<Mesh>);
impl From<Handle<Mesh>> for Mesh3d {
fn from(handle: Handle<Mesh>) -> Self {
Self(handle)
}
}
impl From<Mesh3d> for AssetId<Mesh> {
fn from(mesh: Mesh3d) -> Self {
mesh.id()

View File

@ -16,13 +16,13 @@ use bevy_utils::{
HashMap, HashSet,
};
use core::marker::PhantomData;
use thiserror::Error;
use derive_more::derive::{Display, Error};
#[derive(Debug, Error)]
#[derive(Debug, Error, Display)]
pub enum PrepareAssetError<E: Send + Sync + 'static> {
#[error("Failed to prepare asset")]
#[display("Failed to prepare asset")]
RetryNextUpdate(E),
#[error("Failed to build bind group: {0}")]
#[display("Failed to build bind group: {_0}")]
AsBindGroupError(AsBindGroupError),
}

View File

@ -4,7 +4,7 @@ use crate::{
};
use alloc::borrow::Cow;
use bevy_ecs::entity::Entity;
use thiserror::Error;
use derive_more::derive::{Display, Error};
use super::{InternedRenderSubGraph, RenderSubGraph};
@ -231,19 +231,21 @@ impl<'a> RenderGraphContext<'a> {
}
}
#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum RunSubGraphError {
#[error("attempted to run sub-graph `{0:?}`, but it does not exist")]
#[display("attempted to run sub-graph `{_0:?}`, but it does not exist")]
#[error(ignore)]
MissingSubGraph(InternedRenderSubGraph),
#[error("attempted to pass inputs to sub-graph `{0:?}`, which has no input slots")]
#[display("attempted to pass inputs to sub-graph `{_0:?}`, which has no input slots")]
#[error(ignore)]
SubGraphHasNoInputs(InternedRenderSubGraph),
#[error("sub graph (name: `{graph_name:?}`) could not be run because slot `{slot_name}` at index {slot_index} has no value")]
#[display("sub graph (name: `{graph_name:?}`) could not be run because slot `{slot_name}` at index {slot_index} has no value")]
MissingInput {
slot_index: usize,
slot_name: Cow<'static, str>,
graph_name: InternedRenderSubGraph,
},
#[error("attempted to use the wrong type for input slot")]
#[display("attempted to use the wrong type for input slot")]
MismatchedInputSlotType {
graph_name: InternedRenderSubGraph,
slot_index: usize,
@ -253,11 +255,12 @@ pub enum RunSubGraphError {
},
}
#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum OutputSlotError {
#[error("output slot `{0:?}` does not exist")]
#[display("output slot `{_0:?}` does not exist")]
#[error(ignore)]
InvalidSlot(SlotLabel),
#[error("attempted to output a value of type `{actual}` to output slot `{label:?}`, which has type `{expected}`")]
#[display("attempted to output a value of type `{actual}` to output slot `{label:?}`, which has type `{expected}`")]
MismatchedSlotType {
label: SlotLabel,
expected: SlotType,
@ -265,11 +268,12 @@ pub enum OutputSlotError {
},
}
#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum InputSlotError {
#[error("input slot `{0:?}` does not exist")]
#[display("input slot `{_0:?}` does not exist")]
#[error(ignore)]
InvalidSlot(SlotLabel),
#[error("attempted to retrieve a value of type `{actual}` from input slot `{label:?}`, which has type `{expected}`")]
#[display("attempted to retrieve a value of type `{actual}` from input slot `{label:?}`, which has type `{expected}`")]
MismatchedSlotType {
label: SlotLabel,
expected: SlotType,

View File

@ -12,40 +12,45 @@ pub use graph::*;
pub use node::*;
pub use node_slot::*;
use thiserror::Error;
use derive_more::derive::{Display, Error};
#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum RenderGraphError {
#[error("node {0:?} does not exist")]
#[display("node {_0:?} does not exist")]
#[error(ignore)]
InvalidNode(InternedRenderLabel),
#[error("output node slot does not exist")]
#[display("output node slot does not exist")]
#[error(ignore)]
InvalidOutputNodeSlot(SlotLabel),
#[error("input node slot does not exist")]
#[display("input node slot does not exist")]
#[error(ignore)]
InvalidInputNodeSlot(SlotLabel),
#[error("node does not match the given type")]
#[display("node does not match the given type")]
WrongNodeType,
#[error("attempted to connect output slot {output_slot} from node {output_node:?} to incompatible input slot {input_slot} from node {input_node:?}")]
#[display("attempted to connect output slot {output_slot} from node {output_node:?} to incompatible input slot {input_slot} from node {input_node:?}")]
MismatchedNodeSlots {
output_node: InternedRenderLabel,
output_slot: usize,
input_node: InternedRenderLabel,
input_slot: usize,
},
#[error("attempted to add an edge that already exists")]
#[display("attempted to add an edge that already exists")]
#[error(ignore)]
EdgeAlreadyExists(Edge),
#[error("attempted to remove an edge that does not exist")]
#[display("attempted to remove an edge that does not exist")]
#[error(ignore)]
EdgeDoesNotExist(Edge),
#[error("node {node:?} has an unconnected input slot {input_slot}")]
#[display("node {node:?} has an unconnected input slot {input_slot}")]
UnconnectedNodeInputSlot {
node: InternedRenderLabel,
input_slot: usize,
},
#[error("node {node:?} has an unconnected output slot {output_slot}")]
#[display("node {node:?} has an unconnected output slot {output_slot}")]
UnconnectedNodeOutputSlot {
node: InternedRenderLabel,
output_slot: usize,
},
#[error("node {node:?} input slot {input_slot} already occupied by {occupied_by_node:?}")]
#[display("node {node:?} input slot {input_slot} already occupied by {occupied_by_node:?}")]
NodeInputSlotAlreadyOccupied {
node: InternedRenderLabel,
input_slot: usize,

View File

@ -15,8 +15,8 @@ use bevy_ecs::{
};
use bevy_utils::all_tuples_with_size;
use core::fmt::Debug;
use derive_more::derive::{Display, Error, From};
use downcast_rs::{impl_downcast, Downcast};
use thiserror::Error;
pub use bevy_render_macros::RenderLabel;
@ -90,16 +90,16 @@ pub trait Node: Downcast + Send + Sync + 'static {
impl_downcast!(Node);
#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq, From)]
pub enum NodeRunError {
#[error("encountered an input slot error")]
InputSlotError(#[from] InputSlotError),
#[error("encountered an output slot error")]
OutputSlotError(#[from] OutputSlotError),
#[error("encountered an error when running a sub-graph")]
RunSubGraphError(#[from] RunSubGraphError),
#[error("encountered an error when executing draw command")]
DrawError(#[from] DrawError),
#[display("encountered an input slot error")]
InputSlotError(InputSlotError),
#[display("encountered an output slot error")]
OutputSlotError(OutputSlotError),
#[display("encountered an error when running a sub-graph")]
RunSubGraphError(RunSubGraphError),
#[display("encountered an error when executing draw command")]
DrawError(DrawError),
}
/// A collection of input and output [`Edges`](Edge) for a [`Node`].

View File

@ -1,6 +1,7 @@
use alloc::borrow::Cow;
use bevy_ecs::entity::Entity;
use core::fmt;
use derive_more::derive::From;
use crate::render_resource::{Buffer, Sampler, TextureView};
@ -11,7 +12,7 @@ use crate::render_resource::{Buffer, Sampler, TextureView};
/// [`Buffer`], [`TextureView`], [`Sampler`] and [`Entity`].
///
/// These values do not contain the actual render data, but only the ids to retrieve them.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, From)]
pub enum SlotValue {
/// A GPU-accessible [`Buffer`].
Buffer(Buffer),
@ -35,30 +36,6 @@ impl SlotValue {
}
}
impl From<Buffer> for SlotValue {
fn from(value: Buffer) -> Self {
SlotValue::Buffer(value)
}
}
impl From<TextureView> for SlotValue {
fn from(value: TextureView) -> Self {
SlotValue::TextureView(value)
}
}
impl From<Sampler> for SlotValue {
fn from(value: Sampler) -> Self {
SlotValue::Sampler(value)
}
}
impl From<Entity> for SlotValue {
fn from(value: Entity) -> Self {
SlotValue::Entity(value)
}
}
/// Describes the render resources created (output) or used (input) by
/// the render [`Nodes`](super::Node).
///
@ -90,7 +67,7 @@ impl fmt::Display for SlotType {
/// A [`SlotLabel`] is used to reference a slot by either its name or index
/// inside the [`RenderGraph`](super::RenderGraph).
#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq, From)]
pub enum SlotLabel {
Index(usize),
Name(Cow<'static, str>),
@ -114,18 +91,6 @@ impl From<&'static str> for SlotLabel {
}
}
impl From<Cow<'static, str>> for SlotLabel {
fn from(value: Cow<'static, str>) -> Self {
SlotLabel::Name(value)
}
}
impl From<usize> for SlotLabel {
fn from(value: usize) -> Self {
SlotLabel::Index(value)
}
}
/// The internal representation of a slot, which specifies its [`SlotType`] and name.
#[derive(Clone, Debug)]
pub struct SlotInfo {

View File

@ -8,8 +8,8 @@ use bevy_ecs::{
};
use bevy_utils::{all_tuples, TypeIdMap};
use core::{any::TypeId, fmt::Debug, hash::Hash};
use derive_more::derive::{Display, Error};
use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard};
use thiserror::Error;
/// A draw function used to draw [`PhaseItem`]s.
///
@ -34,13 +34,14 @@ pub trait Draw<P: PhaseItem>: Send + Sync + 'static {
) -> Result<(), DrawError>;
}
#[derive(Error, Debug, PartialEq, Eq)]
#[derive(Error, Display, Debug, PartialEq, Eq)]
pub enum DrawError {
#[error("Failed to execute render command {0:?}")]
#[display("Failed to execute render command {_0:?}")]
#[error(ignore)]
RenderCommandFailure(&'static str),
#[error("Failed to get execute view query")]
#[display("Failed to get execute view query")]
InvalidViewQuery,
#[error("View entity not found")]
#[display("View entity not found")]
ViewEntityNotFound,
}

View File

@ -10,8 +10,8 @@ use alloc::sync::Arc;
use bevy_ecs::system::{SystemParam, SystemParamItem};
pub use bevy_render_macros::AsBindGroup;
use core::ops::Deref;
use derive_more::derive::{Display, Error};
use encase::ShaderType;
use thiserror::Error;
use wgpu::{BindGroupEntry, BindGroupLayoutEntry, BindingResource};
define_atomic_id!(BindGroupId);
@ -354,12 +354,12 @@ pub trait AsBindGroup {
}
/// An error that occurs during [`AsBindGroup::as_bind_group`] calls.
#[derive(Debug, Error)]
#[derive(Debug, Error, Display)]
pub enum AsBindGroupError {
/// The bind group could not be generated. Try again next frame.
#[error("The bind group could not be generated")]
#[display("The bind group could not be generated")]
RetryNextUpdate,
#[error("At binding index{0}, the provided image sampler `{1}` does not match the required sampler type(s) `{2}`.")]
#[display("At binding index{0}, the provided image sampler `{_1}` does not match the required sampler type(s) `{_2}`.")]
InvalidSamplerType(u32, String, String),
}

View File

@ -18,9 +18,9 @@ use bevy_utils::{
HashMap, HashSet,
};
use core::{future::Future, hash::Hash, mem, ops::Deref};
use derive_more::derive::{Display, Error, From};
use naga::valid::Capabilities;
use std::sync::{Mutex, PoisonError};
use thiserror::Error;
#[cfg(feature = "shader_format_spirv")]
use wgpu::util::make_spirv;
use wgpu::{
@ -973,17 +973,19 @@ fn create_pipeline_task(
}
/// Type of error returned by a [`PipelineCache`] when the creation of a GPU pipeline object failed.
#[derive(Error, Debug)]
#[derive(Error, Display, Debug, From)]
pub enum PipelineCacheError {
#[error(
"Pipeline could not be compiled because the following shader could not be loaded: {0:?}"
#[display(
"Pipeline could not be compiled because the following shader could not be loaded: {_0:?}"
)]
#[error(ignore)]
ShaderNotLoaded(AssetId<Shader>),
#[error(transparent)]
ProcessShaderError(#[from] naga_oil::compose::ComposerError),
#[error("Shader import not yet available.")]
ProcessShaderError(naga_oil::compose::ComposerError),
#[display("Shader import not yet available.")]
ShaderImportNotYetAvailable,
#[error("Could not create shader module: {0}")]
#[display("Could not create shader module: {_0}")]
#[error(ignore)]
CreateShaderModule(String),
}

View File

@ -13,7 +13,7 @@ use bevy_utils::{
Entry, HashMap,
};
use core::{fmt::Debug, hash::Hash};
use thiserror::Error;
use derive_more::derive::{Display, Error, From};
pub trait SpecializedRenderPipeline {
type Key: Clone + Hash + PartialEq + Eq;
@ -183,8 +183,7 @@ impl<S: SpecializedMeshPipeline> SpecializedMeshPipelines<S> {
}
}
#[derive(Error, Debug)]
#[derive(Error, Display, Debug, From)]
pub enum SpecializedMeshPipelineError {
#[error(transparent)]
MissingVertexAttribute(#[from] MissingVertexAttributeError),
MissingVertexAttribute(MissingVertexAttributeError),
}

View File

@ -3,24 +3,21 @@ use crate::define_atomic_id;
use alloc::borrow::Cow;
use bevy_asset::{io::Reader, Asset, AssetLoader, AssetPath, Handle, LoadContext};
use bevy_reflect::TypePath;
use bevy_utils::tracing::error;
use core::marker::Copy;
use thiserror::Error;
use derive_more::derive::{Display, Error, From};
define_atomic_id!(ShaderId);
#[derive(Error, Debug)]
#[derive(Error, Display, Debug, From)]
pub enum ShaderReflectError {
#[error(transparent)]
WgslParse(#[from] naga::front::wgsl::ParseError),
WgslParse(naga::front::wgsl::ParseError),
#[cfg(feature = "shader_format_glsl")]
#[error("GLSL Parse Error: {0:?}")]
#[display("GLSL Parse Error: {_0:?}")]
#[error(ignore)]
GlslParse(Vec<naga::front::glsl::Error>),
#[cfg(feature = "shader_format_spirv")]
#[error(transparent)]
SpirVParse(#[from] naga::front::spv::Error),
#[error(transparent)]
Validation(#[from] naga::WithSpan<naga::valid::ValidationError>),
SpirVParse(naga::front::spv::Error),
Validation(naga::WithSpan<naga::valid::ValidationError>),
}
/// A shader, as defined by its [`ShaderSource`](wgpu::ShaderSource) and [`ShaderStage`](naga::ShaderStage)
/// This is an "unprocessed" shader. It can contain preprocessor directives.
@ -247,12 +244,12 @@ impl From<&Source> for naga_oil::compose::ShaderType {
pub struct ShaderLoader;
#[non_exhaustive]
#[derive(Debug, Error)]
#[derive(Debug, Error, Display, From)]
pub enum ShaderLoaderError {
#[error("Could not load shader: {0}")]
Io(#[from] std::io::Error),
#[error("Could not parse shader: {0}")]
Parse(#[from] alloc::string::FromUtf8Error),
#[display("Could not load shader: {_0}")]
Io(std::io::Error),
#[display("Could not parse shader: {_0}")]
Parse(alloc::string::FromUtf8Error),
}
impl AssetLoader for ShaderLoader {

View File

@ -4,8 +4,8 @@ use bevy_utils::tracing::info_span;
use bevy_utils::HashMap;
use alloc::{borrow::Cow, collections::VecDeque};
use derive_more::derive::{Display, Error, From};
use smallvec::{smallvec, SmallVec};
use thiserror::Error;
use crate::{
diagnostic::internal::{DiagnosticsRecorder, RenderDiagnosticsMutex},
@ -29,30 +29,29 @@ use crate::{
/// [`CommandBuffer`]: wgpu::CommandBuffer
pub(crate) struct RenderGraphRunner;
#[derive(Error, Debug)]
#[derive(Error, Display, Debug, From)]
pub enum RenderGraphRunnerError {
#[error(transparent)]
NodeRunError(#[from] NodeRunError),
#[error("node output slot not set (index {slot_index}, name {slot_name})")]
NodeRunError(NodeRunError),
#[display("node output slot not set (index {slot_index}, name {slot_name})")]
EmptyNodeOutputSlot {
type_name: &'static str,
slot_index: usize,
slot_name: Cow<'static, str>,
},
#[error("graph '{sub_graph:?}' could not be run because slot '{slot_name}' at index {slot_index} has no value")]
#[display("graph '{sub_graph:?}' could not be run because slot '{slot_name}' at index {slot_index} has no value")]
MissingInput {
slot_index: usize,
slot_name: Cow<'static, str>,
sub_graph: Option<InternedRenderSubGraph>,
},
#[error("attempted to use the wrong type for input slot")]
#[display("attempted to use the wrong type for input slot")]
MismatchedInputSlotType {
slot_index: usize,
label: SlotLabel,
expected: SlotType,
actual: SlotType,
},
#[error(
#[display(
"node (name: '{node_name:?}') has {slot_count} input slots, but was provided {value_count} values"
)]
MismatchedInputCount {

View File

@ -1,15 +1,14 @@
use super::{Image, ImageFormat, ImageFormatSetting, ImageLoader, ImageLoaderSettings};
use bevy_asset::saver::{AssetSaver, SavedAsset};
use derive_more::derive::{Display, Error, From};
use futures_lite::AsyncWriteExt;
use thiserror::Error;
pub struct CompressedImageSaver;
#[non_exhaustive]
#[derive(Debug, Error)]
#[derive(Debug, Error, Display, From)]
pub enum CompressedImageSaverError {
#[error(transparent)]
Io(#[from] std::io::Error),
Io(std::io::Error),
}
impl AssetSaver for CompressedImageSaver {

View File

@ -1,6 +1,6 @@
use bevy_asset::{io::Reader, AssetLoader, LoadContext};
use bevy_ecs::prelude::{FromWorld, World};
use thiserror::Error;
use derive_more::derive::{Display, Error, From};
use crate::{
render_asset::RenderAssetUsages,
@ -45,12 +45,12 @@ impl Default for ImageLoaderSettings {
}
#[non_exhaustive]
#[derive(Debug, Error)]
#[derive(Debug, Error, Display, From)]
pub enum ImageLoaderError {
#[error("Could load shader: {0}")]
Io(#[from] std::io::Error),
#[error("Could not load texture file: {0}")]
FileTexture(#[from] FileTextureError),
#[display("Could load shader: {_0}")]
Io(std::io::Error),
#[display("Could not load texture file: {_0}")]
FileTexture(FileTextureError),
}
impl AssetLoader for ImageLoader {
@ -120,17 +120,9 @@ impl FromWorld for ImageLoader {
}
/// An error that occurs when loading a texture from a file.
#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
#[display("Error reading image file {path}: {error}, this is an error in `bevy_render`.")]
pub struct FileTextureError {
error: TextureError,
path: String,
}
impl core::fmt::Display for FileTextureError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
write!(
f,
"Error reading image file {}: {}, this is an error in `bevy_render`.",
self.path, self.error
)
}
}