Skip to content

Commit a6adced

Browse files
Deny derive_more error feature and replace it with thiserror (bevyengine#16684)
# Objective - Remove `derive_more`'s error derivation and replace it with `thiserror` ## Solution - Added `derive_more`'s `error` feature to `deny.toml` to prevent it sneaking back in. - Reverted to `thiserror` error derivation ## Notes Merge conflicts were too numerous to revert the individual changes, so this reversion was done manually. Please scrutinise carefully during review.
1 parent d0afdc6 commit a6adced

File tree

102 files changed

+668
-766
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+668
-766
lines changed

crates/bevy_animation/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ ron = "0.8"
3434
serde = "1"
3535
blake3 = { version = "1.0" }
3636
downcast-rs = "1.2.0"
37-
derive_more = { version = "1", default-features = false, features = [
38-
"error",
39-
"from",
40-
"display",
41-
] }
37+
thiserror = { version = "2", default-features = false }
38+
derive_more = { version = "1", default-features = false, features = ["from"] }
4239
either = "1.13"
4340
thread_local = "1"
4441
uuid = { version = "1.7", features = ["v4"] }

crates/bevy_animation/src/gltf_curves.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use bevy_math::{
55
vec4, Quat, Vec4, VectorSpace,
66
};
77
use bevy_reflect::Reflect;
8-
use derive_more::derive::{Display, Error, From};
98
use either::Either;
9+
use thiserror::Error;
1010

1111
/// A keyframe-defined curve that "interpolates" by stepping at `t = 1.0` to the next keyframe.
1212
#[derive(Debug, Clone, Reflect)]
@@ -319,19 +319,20 @@ where
319319
}
320320

321321
/// An error indicating that a multisampling keyframe curve could not be constructed.
322-
#[derive(Debug, Error, Display, From)]
323-
#[display("unable to construct a curve using this data")]
322+
#[derive(Debug, Error)]
323+
#[error("unable to construct a curve using this data")]
324324
pub enum WideKeyframeCurveError {
325325
/// The number of given values was not divisible by a multiple of the number of keyframes.
326-
#[display("number of values ({values_given}) is not divisible by {divisor}")]
326+
#[error("number of values ({values_given}) is not divisible by {divisor}")]
327327
LengthMismatch {
328328
/// The number of values given.
329329
values_given: usize,
330330
/// The number that `values_given` was supposed to be divisible by.
331331
divisor: usize,
332332
},
333333
/// An error was returned by the internal core constructor.
334-
CoreError(ChunkedUnevenCoreError),
334+
#[error(transparent)]
335+
CoreError(#[from] ChunkedUnevenCoreError),
335336
}
336337

337338
impl<T> WideCubicKeyframeCurve<T> {

crates/bevy_animation/src/graph.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ use bevy_ecs::{
1616
};
1717
use bevy_reflect::{prelude::ReflectDefault, Reflect, ReflectSerialize};
1818
use bevy_utils::HashMap;
19-
use derive_more::derive::{Display, Error, From};
19+
use derive_more::derive::From;
2020
use petgraph::{
2121
graph::{DiGraph, NodeIndex},
2222
Direction,
2323
};
2424
use ron::de::SpannedError;
2525
use serde::{Deserialize, Serialize};
2626
use smallvec::SmallVec;
27+
use thiserror::Error;
2728

2829
use crate::{AnimationClip, AnimationTargetId};
2930

@@ -237,18 +238,18 @@ pub struct AnimationGraphAssetLoader;
237238

238239
/// Various errors that can occur when serializing or deserializing animation
239240
/// graphs to and from RON, respectively.
240-
#[derive(Error, Display, Debug, From)]
241+
#[derive(Error, Debug)]
241242
pub enum AnimationGraphLoadError {
242243
/// An I/O error occurred.
243-
#[display("I/O")]
244-
Io(io::Error),
244+
#[error("I/O")]
245+
Io(#[from] io::Error),
245246
/// An error occurred in RON serialization or deserialization.
246-
#[display("RON serialization")]
247-
Ron(ron::Error),
247+
#[error("RON serialization")]
248+
Ron(#[from] ron::Error),
248249
/// An error occurred in RON deserialization, and the location of the error
249250
/// is supplied.
250-
#[display("RON serialization")]
251-
SpannedRon(SpannedError),
251+
#[error("RON serialization")]
252+
SpannedRon(#[from] SpannedError),
252253
}
253254

254255
/// Acceleration structures for animation graphs that allows Bevy to evaluate

crates/bevy_app/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.15.0-dev" }
2929

3030
# other
3131
downcast-rs = "1.2.0"
32-
derive_more = { version = "1", default-features = false, features = [
33-
"error",
34-
"from",
35-
"display",
36-
] }
32+
thiserror = { version = "2", default-features = false }
3733
variadics_please = "1.0"
3834

3935
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

crates/bevy_app/src/app.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use bevy_ecs::{
1515
use bevy_utils::tracing::info_span;
1616
use bevy_utils::{tracing::debug, HashMap};
1717
use core::{fmt::Debug, num::NonZero, panic::AssertUnwindSafe};
18-
use derive_more::derive::{Display, Error};
1918
use std::{
2019
panic::{catch_unwind, resume_unwind},
2120
process::{ExitCode, Termination},
2221
};
22+
use thiserror::Error;
2323

2424
bevy_ecs::define_label!(
2525
/// A strongly-typed class of labels used to identify an [`App`].
@@ -32,9 +32,9 @@ pub use bevy_ecs::label::DynEq;
3232
/// A shorthand for `Interned<dyn AppLabel>`.
3333
pub type InternedAppLabel = Interned<dyn AppLabel>;
3434

35-
#[derive(Debug, Error, Display)]
35+
#[derive(Debug, Error)]
3636
pub(crate) enum AppError {
37-
#[display("duplicate plugin {plugin_name:?}")]
37+
#[error("duplicate plugin {plugin_name:?}")]
3838
DuplicatePlugin { plugin_name: String },
3939
}
4040

crates/bevy_asset/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ blake3 = "1.5"
4444
parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] }
4545
ron = "0.8"
4646
serde = { version = "1", features = ["derive"] }
47-
derive_more = { version = "1", default-features = false, features = [
48-
"error",
49-
"from",
50-
"display",
51-
] }
47+
thiserror = { version = "2", default-features = false }
48+
derive_more = { version = "1", default-features = false, features = ["from"] }
5249
uuid = { version = "1.0", features = ["v4"] }
5350

5451
[target.'cfg(target_os = "android")'.dependencies]

crates/bevy_asset/src/assets.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use bevy_reflect::{Reflect, TypePath};
1111
use bevy_utils::HashMap;
1212
use core::{any::TypeId, iter::Enumerate, marker::PhantomData, sync::atomic::AtomicU32};
1313
use crossbeam_channel::{Receiver, Sender};
14-
use derive_more::derive::{Display, Error};
1514
use serde::{Deserialize, Serialize};
15+
use thiserror::Error;
1616
use uuid::Uuid;
1717

1818
/// A generational runtime-only identifier for a specific [`Asset`] stored in [`Assets`]. This is optimized for efficient runtime
@@ -613,8 +613,8 @@ impl<'a, A: Asset> Iterator for AssetsMutIterator<'a, A> {
613613
}
614614
}
615615

616-
#[derive(Error, Display, Debug)]
617-
#[display("AssetIndex {index:?} has an invalid generation. The current generation is: '{current_generation}'.")]
616+
#[derive(Error, Debug)]
617+
#[error("AssetIndex {index:?} has an invalid generation. The current generation is: '{current_generation}'.")]
618618
pub struct InvalidGenerationError {
619619
index: AssetIndex,
620620
current_generation: u32,

crates/bevy_asset/src/handle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use core::{
99
hash::{Hash, Hasher},
1010
};
1111
use crossbeam_channel::{Receiver, Sender};
12-
use derive_more::derive::{Display, Error};
1312
use disqualified::ShortName;
13+
use thiserror::Error;
1414
use uuid::Uuid;
1515

1616
/// Provides [`Handle`] and [`UntypedHandle`] _for a specific asset type_.
@@ -502,11 +502,11 @@ impl<A: Asset> TryFrom<UntypedHandle> for Handle<A> {
502502
}
503503

504504
/// Errors preventing the conversion of to/from an [`UntypedHandle`] and a [`Handle`].
505-
#[derive(Error, Display, Debug, PartialEq, Clone)]
505+
#[derive(Error, Debug, PartialEq, Clone)]
506506
#[non_exhaustive]
507507
pub enum UntypedAssetConversionError {
508508
/// Caused when trying to convert an [`UntypedHandle`] into a [`Handle`] of the wrong type.
509-
#[display(
509+
#[error(
510510
"This UntypedHandle is for {found:?} and cannot be converted into a Handle<{expected:?}>"
511511
)]
512512
TypeIdMismatch { expected: TypeId, found: TypeId },

crates/bevy_asset/src/id.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use core::{
99
hash::Hash,
1010
marker::PhantomData,
1111
};
12-
use derive_more::derive::{Display, Error, From};
12+
use derive_more::derive::From;
13+
use thiserror::Error;
1314

1415
/// A unique runtime-only identifier for an [`Asset`]. This is cheap to [`Copy`]/[`Clone`] and is not directly tied to the
1516
/// lifetime of the Asset. This means it _can_ point to an [`Asset`] that no longer exists.
@@ -398,11 +399,11 @@ impl<A: Asset> TryFrom<UntypedAssetId> for AssetId<A> {
398399
}
399400

400401
/// Errors preventing the conversion of to/from an [`UntypedAssetId`] and an [`AssetId`].
401-
#[derive(Error, Display, Debug, PartialEq, Clone)]
402+
#[derive(Error, Debug, PartialEq, Clone)]
402403
#[non_exhaustive]
403404
pub enum UntypedAssetIdConversionError {
404405
/// Caused when trying to convert an [`UntypedAssetId`] into an [`AssetId`] of the wrong type.
405-
#[display("This UntypedAssetId is for {found:?} and cannot be converted into an AssetId<{expected:?}>")]
406+
#[error("This UntypedAssetId is for {found:?} and cannot be converted into an AssetId<{expected:?}>")]
406407
TypeIdMismatch { expected: TypeId, found: TypeId },
407408
}
408409

crates/bevy_asset/src/io/mod.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,25 @@ use core::{
2929
pin::Pin,
3030
task::{Context, Poll},
3131
};
32-
use derive_more::derive::{Display, Error, From};
3332
use futures_io::{AsyncRead, AsyncWrite};
3433
use futures_lite::{ready, Stream};
3534
use std::path::{Path, PathBuf};
35+
use thiserror::Error;
3636

3737
/// Errors that occur while loading assets.
38-
#[derive(Error, Display, Debug, Clone)]
38+
#[derive(Error, Debug, Clone)]
3939
pub enum AssetReaderError {
4040
/// Path not found.
41-
#[display("Path not found: {}", _0.display())]
42-
#[error(ignore)]
41+
#[error("Path not found: {}", _0.display())]
4342
NotFound(PathBuf),
4443

4544
/// Encountered an I/O error while loading an asset.
46-
#[display("Encountered an I/O error while loading asset: {_0}")]
45+
#[error("Encountered an I/O error while loading asset: {0}")]
4746
Io(Arc<std::io::Error>),
4847

4948
/// The HTTP request completed but returned an unhandled [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status).
5049
/// If the request fails before getting a status code (e.g. request timeout, interrupted connection, etc), expect [`AssetReaderError::Io`].
51-
#[display("Encountered HTTP status {_0:?} when loading asset")]
52-
#[error(ignore)]
50+
#[error("Encountered HTTP status {0:?} when loading asset")]
5351
HttpError(u16),
5452
}
5553

@@ -333,11 +331,11 @@ pub type Writer = dyn AsyncWrite + Unpin + Send + Sync;
333331
pub type PathStream = dyn Stream<Item = PathBuf> + Unpin + Send;
334332

335333
/// Errors that occur while loading assets.
336-
#[derive(Error, Display, Debug, From)]
334+
#[derive(Error, Debug)]
337335
pub enum AssetWriterError {
338336
/// Encountered an I/O error while loading an asset.
339-
#[display("encountered an io error while loading asset: {_0}")]
340-
Io(std::io::Error),
337+
#[error("encountered an io error while loading asset: {0}")]
338+
Io(#[from] std::io::Error),
341339
}
342340

343341
/// Preforms write operations on an asset storage. [`AssetWriter`] exposes a "virtual filesystem"

0 commit comments

Comments
 (0)