pub enum Error {
Show 17 variants
InvalidHandle(u32),
BodyNotFound(u32),
ColliderNotFound(u32),
InvalidParameter {
name: String,
message: String,
},
InvalidMass(f64),
InvalidTimeStep(f64),
InvalidDimension(f64),
CapacityExceeded {
max: usize,
},
SimulationDiverged {
step: u64,
},
SolverConvergenceFailed {
iterations: u32,
},
BodySleeping(u32),
Serialization(String),
SnapshotValidation(String),
TypeError {
expected: String,
got: String,
},
MissingArgument(String),
WrongArrayLength {
expected: usize,
got: usize,
},
General(String),
}Expand description
Comprehensive error type for the oxiphysics-python bridge.
Every failure mode has a dedicated variant to allow fine-grained handling
from Python user code and for clean mapping to PyErr via PyO3.
Variants§
InvalidHandle(u32)
A body or object handle was invalid.
BodyNotFound(u32)
A rigid body was not found by handle.
ColliderNotFound(u32)
A collider was not found by handle.
InvalidParameter
A named parameter was out of its valid range.
InvalidMass(f64)
A mass value was non-positive.
InvalidTimeStep(f64)
A time step was non-positive.
InvalidDimension(f64)
A geometry dimension was non-positive.
CapacityExceeded
The world has reached its maximum body capacity.
SimulationDiverged
The simulation has diverged (NaN / Inf detected).
SolverConvergenceFailed
The solver failed to converge.
BodySleeping(u32)
A body was queried but it is sleeping.
Serialization(String)
JSON serialization or deserialization failed.
SnapshotValidation(String)
Snapshot validation failed (schema mismatch, missing fields, etc.).
TypeError
A Python argument had an unexpected type.
MissingArgument(String)
A required Python keyword argument was missing.
WrongArrayLength
A Python list or array had the wrong length.
General(String)
Generic error with a free-form message.
Implementations§
Source§impl Error
impl Error
Sourcepub fn invalid_param(
name: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn invalid_param( name: impl Into<String>, message: impl Into<String>, ) -> Self
Create an InvalidParameter error.
Sourcepub fn type_error(expected: impl Into<String>, got: impl Into<String>) -> Self
pub fn type_error(expected: impl Into<String>, got: impl Into<String>) -> Self
Create a TypeError error.
Sourcepub fn is_handle_error(&self) -> bool
pub fn is_handle_error(&self) -> bool
Returns true if this error is handle-related.
Sourcepub fn is_parameter_error(&self) -> bool
pub fn is_parameter_error(&self) -> bool
Returns true if this error is a parameter validation error.
Sourcepub fn is_capacity_error(&self) -> bool
pub fn is_capacity_error(&self) -> bool
Returns true if this error is capacity-related.
Sourcepub fn is_stability_error(&self) -> bool
pub fn is_stability_error(&self) -> bool
Returns true if this error indicates simulation instability.
Sourcepub fn is_serialization_error(&self) -> bool
pub fn is_serialization_error(&self) -> bool
Returns true if this is a serialization error.
Sourcepub fn is_type_error(&self) -> bool
pub fn is_type_error(&self) -> bool
Returns true if this is a Python interop type error.
Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Serialize this error to a JSON string for Python exception chaining.
§Example
use oxiphysics_python::Error;
let e = Error::InvalidTimeStep(-0.1);
let json = e.to_json();
assert!(json.contains("InvalidTimeStep"));Sourcepub fn python_exception_class(&self) -> &'static str
pub fn python_exception_class(&self) -> &'static str
Return a Python exception class name that best maps to this error.
Useful when calling PyO3’s PyErr::new::<PyXxx, _>().
Sourcepub fn recovery_hint(&self) -> String
pub fn recovery_hint(&self) -> String
Return a human-readable recovery hint for this error.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Error
impl<'de> Deserialize<'de> for Error
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.