Skip to main content

gizmo_physics_core/
error.rs

1use crate::BodyHandle;
2use std::fmt;
3
4#[derive(Debug, Clone, PartialEq)]
5#[non_exhaustive]
6pub enum GizmoError {
7    CollisionOverflow { count: usize, limit: usize },
8    NaNVelocity(BodyHandle),
9    NaNPosition(BodyHandle),
10    InvalidConstraint(String),
11    DivideByZero(BodyHandle),
12    TunnelingDetected(BodyHandle),
13    BvhBuildFailed,
14    JointEntityNotFound(BodyHandle),
15    InvalidShapeData(String),
16    SleepStateCorrupted(BodyHandle),
17}
18
19impl fmt::Display for GizmoError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            GizmoError::CollisionOverflow { count, limit } => write!(
23                f,
24                "Too many collisions detected (count: {}, limit: {})",
25                count, limit
26            ),
27            GizmoError::NaNVelocity(ent) => {
28                write!(f, "NaN velocity detected for entity: {:?}", ent)
29            }
30            GizmoError::NaNPosition(ent) => {
31                write!(f, "NaN position detected for entity: {:?}", ent)
32            }
33            GizmoError::InvalidConstraint(msg) => write!(f, "Invalid constraint: {}", msg),
34            GizmoError::DivideByZero(ent) => {
35                write!(f, "Divide by zero encountered for entity: {:?}", ent)
36            }
37            GizmoError::TunnelingDetected(ent) => {
38                write!(f, "Tunneling detected for entity: {:?}", ent)
39            }
40            GizmoError::BvhBuildFailed => write!(f, "BVH build failed"),
41            GizmoError::JointEntityNotFound(ent) => {
42                write!(f, "Joint entity not found in entity_index_map: {:?}", ent)
43            }
44            GizmoError::InvalidShapeData(msg) => {
45                write!(f, "Invalid shape data (degenerate shape): {}", msg)
46            }
47            GizmoError::SleepStateCorrupted(ent) => {
48                write!(f, "Sleep/wake state corrupted for entity: {:?}", ent)
49            }
50        }
51    }
52}
53
54impl std::error::Error for GizmoError {
55    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
56        // İleride wrapped inner error'lar eklenirse buradan return edilebilir.
57        // Şimdilik herhangi bir variant alt hata barındırmadığı için None dönüyoruz.
58        None
59    }
60}