Skip to content

Commit cb62851

Browse files
shafferchanceshafferchance-luluChanceler Shaffer
authored
Add core Error to InvalidDirectionError (#17820)
# Objective Fixes #17761 ## Solution - Added core error to InvalidDirectionError ## Testing - Did you test these changes? If so, how? - An added test that pulls in anyhow as a dev dependency to ensure the conversion is accounted for in creation via From - Are there any parts that need more testing? - I'm unsure but probably not due to being a trivial change - How can other people (reviewers) test your changes? Is there anything specific they need to know? - I did not try a fully built version of Bevy. Relied purely on tests. - If relevant, what platforms did you test these changes on, and are there any important ones you can't test? - Only windows --------- Co-authored-by: Chanceler Shaffer <[email protected]> Co-authored-by: Chanceler Shaffer <[email protected]>
1 parent d76c782 commit cb62851

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

crates/bevy_math/src/direction.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
1515
#[cfg(all(debug_assertions, feature = "std"))]
1616
use std::eprintln;
1717

18+
use thiserror::Error;
19+
1820
/// An error indicating that a direction is invalid.
19-
#[derive(Debug, PartialEq)]
21+
#[derive(Debug, PartialEq, Error)]
2022
pub enum InvalidDirectionError {
2123
/// The length of the direction vector is zero or very close to zero.
24+
#[error("The length of the direction vector is zero or very close to zero")]
2225
Zero,
2326
/// The length of the direction vector is `std::f32::INFINITY`.
27+
#[error("The length of the direction vector is `std::f32::INFINITY`")]
2428
Infinite,
2529
/// The length of the direction vector is `NaN`.
30+
#[error("The length of the direction vector is `NaN`")]
2631
NaN,
2732
}
2833

@@ -41,15 +46,6 @@ impl InvalidDirectionError {
4146
}
4247
}
4348

44-
impl core::fmt::Display for InvalidDirectionError {
45-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46-
write!(
47-
f,
48-
"Direction can not be zero (or very close to zero), or non-finite."
49-
)
50-
}
51-
}
52-
5349
/// Checks that a vector with the given squared length is normalized.
5450
///
5551
/// Warns for small error with a length threshold of approximately `1e-4`,

0 commit comments

Comments
 (0)