Skip to main content

Error

Enum Error 

Source
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.

Fields

§name: String

Parameter name.

§message: String

Constraint description.

§

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.

Fields

§max: usize

Maximum allowed bodies.

§

SimulationDiverged

The simulation has diverged (NaN / Inf detected).

Fields

§step: u64

Step at which divergence was detected.

§

SolverConvergenceFailed

The solver failed to converge.

Fields

§iterations: u32

Iterations attempted.

§

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.

Fields

§expected: String

Expected Python type name.

§got: String

Actual Python type name.

§

MissingArgument(String)

A required Python keyword argument was missing.

§

WrongArrayLength

A Python list or array had the wrong length.

Fields

§expected: usize

Expected length.

§got: usize

Actual length.

§

General(String)

Generic error with a free-form message.

Implementations§

Source§

impl Error

Source

pub fn invalid_param( name: impl Into<String>, message: impl Into<String>, ) -> Self

Create an InvalidParameter error.

Source

pub fn general(msg: impl Into<String>) -> Self

Create a General error.

Source

pub fn type_error(expected: impl Into<String>, got: impl Into<String>) -> Self

Create a TypeError error.

Source

pub fn wrong_len(expected: usize, got: usize) -> Self

Create a WrongArrayLength error.

Source

pub fn is_handle_error(&self) -> bool

Returns true if this error is handle-related.

Source

pub fn is_parameter_error(&self) -> bool

Returns true if this error is a parameter validation error.

Source

pub fn is_capacity_error(&self) -> bool

Returns true if this error is capacity-related.

Source

pub fn is_stability_error(&self) -> bool

Returns true if this error indicates simulation instability.

Source

pub fn is_serialization_error(&self) -> bool

Returns true if this is a serialization error.

Source

pub fn is_type_error(&self) -> bool

Returns true if this is a Python interop type error.

Source

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"));
Source

pub fn from_json(json: &str) -> Result<Self, String>

Deserialize an Error from JSON.

Source

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, _>().

Source

pub fn recovery_hint(&self) -> String

Return a human-readable recovery hint for this error.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Error

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Error) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Error

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,