structecs/
error.rs

1use std::fmt;
2
3use crate::EntityId;
4
5/// Errors that can occur when interacting with the World.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum WorldError {
8    /// The specified entity was not found in the world.
9    EntityNotFound(EntityId),
10
11    /// The requested component type was not found on the entity.
12    ComponentNotFound {
13        entity_id: EntityId,
14        component_name: &'static str,
15    },
16
17    /// Batch removal completed with some failures.
18    /// Contains the list of successfully removed entities and failed entities.
19    PartialRemoval {
20        succeeded: Vec<EntityId>,
21        failed: Vec<EntityId>,
22    },
23
24    /// The archetype for the entity was not found (internal consistency error).
25    ///
26    /// This error indicates an internal inconsistency in the World state
27    /// and should not normally occur. If you encounter this error, please
28    /// file a bug report.
29    #[doc(hidden)]
30    ArchetypeNotFound(EntityId),
31}
32
33impl fmt::Display for WorldError {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        match self {
36            WorldError::EntityNotFound(id) => {
37                write!(f, "Entity {} not found in world", id)
38            }
39            WorldError::ComponentNotFound {
40                entity_id,
41                component_name,
42            } => {
43                write!(
44                    f,
45                    "Component '{}' not found on entity {}",
46                    component_name, entity_id
47                )
48            }
49            WorldError::PartialRemoval { succeeded, failed } => {
50                write!(
51                    f,
52                    "Batch removal partially succeeded: {} removed, {} failed",
53                    succeeded.len(),
54                    failed.len()
55                )
56            }
57            WorldError::ArchetypeNotFound(id) => {
58                write!(f, "Archetype not found for entity {} (internal error)", id)
59            }
60        }
61    }
62}
63
64impl std::error::Error for WorldError {}