Skip to main content

cougr_core/
error.rs

1use soroban_sdk::contracterror;
2
3/// Error types for the Cougr ECS framework.
4///
5/// Uses `#[contracterror]` for Soroban contract compatibility.
6/// Each variant maps to a `u32` error code for on-chain error reporting.
7#[contracterror]
8#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
9#[repr(u32)]
10pub enum CougrError {
11    /// Entity with the given ID was not found
12    EntityNotFound = 1,
13    /// Component not found for the given entity
14    ComponentNotFound = 2,
15    /// Failed to deserialize component/resource data
16    DeserializationFailed = 3,
17    /// Data length does not match expected size
18    InvalidDataLength = 4,
19    /// Index out of bounds during storage access
20    IndexOutOfBounds = 5,
21    /// Resource with the given type was not found
22    ResourceNotFound = 6,
23    /// Storage operation failed
24    StorageError = 7,
25}
26
27/// Convenience type alias for Results using CougrError
28pub type CougrResult<T> = Result<T, CougrError>;