From 8718adc74f2da6100f366052a6aeec4f659e09b0 Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Thu, 10 Oct 2024 01:26:28 +1100 Subject: [PATCH] Remove `thiserror` from `bevy_render` (#15765) # Objective - Contributes to #15460 ## Solution - Removed `thiserror` from `bevy_render` --- crates/bevy_render/Cargo.toml | 6 ++- crates/bevy_render/src/camera/camera.rs | 11 ++--- crates/bevy_render/src/camera/clear_color.rs | 9 +--- crates/bevy_render/src/camera/projection.rs | 15 +------ crates/bevy_render/src/mesh/components.rs | 17 ++------ crates/bevy_render/src/render_asset.rs | 8 ++-- .../bevy_render/src/render_graph/context.rs | 28 +++++++------ crates/bevy_render/src/render_graph/mod.rs | 29 +++++++------ crates/bevy_render/src/render_graph/node.rs | 20 ++++----- .../bevy_render/src/render_graph/node_slot.rs | 41 ++----------------- crates/bevy_render/src/render_phase/draw.rs | 11 ++--- .../src/render_resource/bind_group.rs | 8 ++-- .../src/render_resource/pipeline_cache.rs | 18 ++++---- .../render_resource/pipeline_specializer.rs | 7 ++-- .../bevy_render/src/render_resource/shader.rs | 27 ++++++------ .../bevy_render/src/renderer/graph_runner.rs | 15 ++++--- .../src/texture/compressed_image_saver.rs | 7 ++-- .../bevy_render/src/texture/image_loader.rs | 24 ++++------- 18 files changed, 118 insertions(+), 183 deletions(-) diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index ab3603e0f53a1..1d0b820887e61 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -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 diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 3aded842ea665..58fda6529c891 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -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> for RenderTarget { - fn from(handle: Handle) -> 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), diff --git a/crates/bevy_render/src/camera/clear_color.rs b/crates/bevy_render/src/camera/clear_color.rs index e1cb54a39e809..49dbdea76bf2a 100644 --- a/crates/bevy_render/src/camera/clear_color.rs +++ b/crates/bevy_render/src/camera/clear_color.rs @@ -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 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, diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index e29d4ec869d8e..486acb91ee1db 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -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 for Projection { - fn from(p: PerspectiveProjection) -> Self { - Self::Perspective(p) - } -} - -impl From for Projection { - fn from(p: OrthographicProjection) -> Self { - Self::Orthographic(p) - } -} - impl CameraProjection for Projection { fn get_clip_from_view(&self) -> Mat4 { match self { diff --git a/crates/bevy_render/src/mesh/components.rs b/crates/bevy_render/src/mesh/components.rs index 89ff93e76bfa8..cb3d46afa4e6b 100644 --- a/crates/bevy_render/src/mesh/components.rs +++ b/crates/bevy_render/src/mesh/components.rs @@ -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); -impl From> for Mesh2d { - fn from(handle: Handle) -> Self { - Self(handle) - } -} - impl From for AssetId { fn from(mesh: Mesh2d) -> Self { mesh.id() @@ -91,17 +86,11 @@ impl From<&Mesh2d> for AssetId { /// )); /// } /// ``` -#[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); -impl From> for Mesh3d { - fn from(handle: Handle) -> Self { - Self(handle) - } -} - impl From for AssetId { fn from(mesh: Mesh3d) -> Self { mesh.id() diff --git a/crates/bevy_render/src/render_asset.rs b/crates/bevy_render/src/render_asset.rs index 73d23e106cf65..9fc802ed85503 100644 --- a/crates/bevy_render/src/render_asset.rs +++ b/crates/bevy_render/src/render_asset.rs @@ -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 { - #[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), } diff --git a/crates/bevy_render/src/render_graph/context.rs b/crates/bevy_render/src/render_graph/context.rs index c27f269d0ba45..4a99dc07b5025 100644 --- a/crates/bevy_render/src/render_graph/context.rs +++ b/crates/bevy_render/src/render_graph/context.rs @@ -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, diff --git a/crates/bevy_render/src/render_graph/mod.rs b/crates/bevy_render/src/render_graph/mod.rs index fbed33a23c6f4..4769e1dc1400c 100644 --- a/crates/bevy_render/src/render_graph/mod.rs +++ b/crates/bevy_render/src/render_graph/mod.rs @@ -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, diff --git a/crates/bevy_render/src/render_graph/node.rs b/crates/bevy_render/src/render_graph/node.rs index 9406baf580d02..1e0243e31cdff 100644 --- a/crates/bevy_render/src/render_graph/node.rs +++ b/crates/bevy_render/src/render_graph/node.rs @@ -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`]. diff --git a/crates/bevy_render/src/render_graph/node_slot.rs b/crates/bevy_render/src/render_graph/node_slot.rs index 81a736754017e..eb11b368cd7bb 100644 --- a/crates/bevy_render/src/render_graph/node_slot.rs +++ b/crates/bevy_render/src/render_graph/node_slot.rs @@ -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 for SlotValue { - fn from(value: Buffer) -> Self { - SlotValue::Buffer(value) - } -} - -impl From for SlotValue { - fn from(value: TextureView) -> Self { - SlotValue::TextureView(value) - } -} - -impl From for SlotValue { - fn from(value: Sampler) -> Self { - SlotValue::Sampler(value) - } -} - -impl From 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> for SlotLabel { - fn from(value: Cow<'static, str>) -> Self { - SlotLabel::Name(value) - } -} - -impl From 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 { diff --git a/crates/bevy_render/src/render_phase/draw.rs b/crates/bevy_render/src/render_phase/draw.rs index 2deafa4bf2396..44356331bc705 100644 --- a/crates/bevy_render/src/render_phase/draw.rs +++ b/crates/bevy_render/src/render_phase/draw.rs @@ -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: 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, } diff --git a/crates/bevy_render/src/render_resource/bind_group.rs b/crates/bevy_render/src/render_resource/bind_group.rs index 7e9a5ae3e1b0a..d8d054a8ea50e 100644 --- a/crates/bevy_render/src/render_resource/bind_group.rs +++ b/crates/bevy_render/src/render_resource/bind_group.rs @@ -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), } diff --git a/crates/bevy_render/src/render_resource/pipeline_cache.rs b/crates/bevy_render/src/render_resource/pipeline_cache.rs index 3db03bdff3e44..1cb64d06bff32 100644 --- a/crates/bevy_render/src/render_resource/pipeline_cache.rs +++ b/crates/bevy_render/src/render_resource/pipeline_cache.rs @@ -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), - #[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), } diff --git a/crates/bevy_render/src/render_resource/pipeline_specializer.rs b/crates/bevy_render/src/render_resource/pipeline_specializer.rs index 55c13b3ab154c..7656fd57d6729 100644 --- a/crates/bevy_render/src/render_resource/pipeline_specializer.rs +++ b/crates/bevy_render/src/render_resource/pipeline_specializer.rs @@ -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 SpecializedMeshPipelines { } } -#[derive(Error, Debug)] +#[derive(Error, Display, Debug, From)] pub enum SpecializedMeshPipelineError { - #[error(transparent)] - MissingVertexAttribute(#[from] MissingVertexAttributeError), + MissingVertexAttribute(MissingVertexAttributeError), } diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index c6c37c6a6232c..3c271541e4ab7 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -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), #[cfg(feature = "shader_format_spirv")] - #[error(transparent)] - SpirVParse(#[from] naga::front::spv::Error), - #[error(transparent)] - Validation(#[from] naga::WithSpan), + SpirVParse(naga::front::spv::Error), + Validation(naga::WithSpan), } /// 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 { diff --git a/crates/bevy_render/src/renderer/graph_runner.rs b/crates/bevy_render/src/renderer/graph_runner.rs index 15b3240638e7c..f2e90d33ea986 100644 --- a/crates/bevy_render/src/renderer/graph_runner.rs +++ b/crates/bevy_render/src/renderer/graph_runner.rs @@ -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, }, - #[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 { diff --git a/crates/bevy_render/src/texture/compressed_image_saver.rs b/crates/bevy_render/src/texture/compressed_image_saver.rs index 2923d4b8d1c2d..2528456e8f365 100644 --- a/crates/bevy_render/src/texture/compressed_image_saver.rs +++ b/crates/bevy_render/src/texture/compressed_image_saver.rs @@ -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 { diff --git a/crates/bevy_render/src/texture/image_loader.rs b/crates/bevy_render/src/texture/image_loader.rs index 9f3c55502eddc..73992f1f05e9e 100644 --- a/crates/bevy_render/src/texture/image_loader.rs +++ b/crates/bevy_render/src/texture/image_loader.rs @@ -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 - ) - } -}