Skip to main content

gizmo_physics_core/
error.rs

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