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 <cshaffer2@lululemon.com>
Co-authored-by: Chanceler Shaffer <chancelershaffer@lululemon.com>
This commit is contained in:
Chanceler Shaffer 2025-02-24 13:04:22 -08:00 committed by GitHub
parent d76c782f39
commit cb628516d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,14 +15,19 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
#[cfg(all(debug_assertions, feature = "std"))] #[cfg(all(debug_assertions, feature = "std"))]
use std::eprintln; use std::eprintln;
use thiserror::Error;
/// An error indicating that a direction is invalid. /// An error indicating that a direction is invalid.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Error)]
pub enum InvalidDirectionError { pub enum InvalidDirectionError {
/// The length of the direction vector is zero or very close to zero. /// The length of the direction vector is zero or very close to zero.
#[error("The length of the direction vector is zero or very close to zero")]
Zero, Zero,
/// The length of the direction vector is `std::f32::INFINITY`. /// The length of the direction vector is `std::f32::INFINITY`.
#[error("The length of the direction vector is `std::f32::INFINITY`")]
Infinite, Infinite,
/// The length of the direction vector is `NaN`. /// The length of the direction vector is `NaN`.
#[error("The length of the direction vector is `NaN`")]
NaN, NaN,
} }
@ -41,15 +46,6 @@ impl InvalidDirectionError {
} }
} }
impl core::fmt::Display for InvalidDirectionError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"Direction can not be zero (or very close to zero), or non-finite."
)
}
}
/// Checks that a vector with the given squared length is normalized. /// Checks that a vector with the given squared length is normalized.
/// ///
/// Warns for small error with a length threshold of approximately `1e-4`, /// Warns for small error with a length threshold of approximately `1e-4`,