Skip to main content

agentic_reality/types/
error.rs

1//! Error types for AgenticReality.
2
3use thiserror::Error;
4
5/// Result type alias for AgenticReality operations.
6pub type RealityResult<T> = Result<T, RealityError>;
7
8/// All errors that can occur in AgenticReality.
9#[derive(Error, Debug)]
10pub enum RealityError {
11    #[error("IO error: {0}")]
12    Io(#[from] std::io::Error),
13
14    #[error("Serialization error: {0}")]
15    Serialization(String),
16
17    #[error("Invalid format: {0}")]
18    InvalidFormat(String),
19
20    #[error("Invalid magic bytes")]
21    InvalidMagic,
22
23    #[error("Version mismatch: expected {expected}, got {got}")]
24    VersionMismatch { expected: u32, got: u32 },
25
26    #[error("Checksum mismatch: expected {expected}, got {got}")]
27    ChecksumMismatch { expected: String, got: String },
28
29    #[error("Section not found: {0}")]
30    SectionNotFound(String),
31
32    #[error("Not initialized: {0}")]
33    NotInitialized(String),
34
35    #[error("Already initialized: {0}")]
36    AlreadyInitialized(String),
37
38    #[error("Not found: {0}")]
39    NotFound(String),
40
41    #[error("Duplicate: {0}")]
42    Duplicate(String),
43
44    #[error("Validation error: {0}")]
45    Validation(String),
46
47    #[error("Invalid operation: {0}")]
48    InvalidOperation(String),
49
50    #[error("Invalid parameter: {field} — {reason}")]
51    InvalidParameter { field: String, reason: String },
52
53    #[error("Missing required field: {0}")]
54    MissingField(String),
55
56    #[error("Authentication error: {0}")]
57    Authentication(String),
58
59    #[error("Authorization error: {0}")]
60    Authorization(String),
61
62    #[error("Encryption error: {0}")]
63    Encryption(String),
64
65    #[error("Capacity exceeded: {0}")]
66    CapacityExceeded(String),
67
68    #[error("Transition error: {0}")]
69    TransitionError(String),
70
71    #[error("Coherence violation: {0}")]
72    CoherenceViolation(String),
73
74    #[error("Bridge error: {bridge} — {message}")]
75    BridgeError { bridge: String, message: String },
76
77    #[error("Internal error: {0}")]
78    Internal(String),
79}
80
81impl From<serde_json::Error> for RealityError {
82    fn from(e: serde_json::Error) -> Self {
83        RealityError::Serialization(e.to_string())
84    }
85}
86
87impl From<bincode::Error> for RealityError {
88    fn from(e: bincode::Error) -> Self {
89        RealityError::Serialization(e.to_string())
90    }
91}
92
93impl From<uuid::Error> for RealityError {
94    fn from(e: uuid::Error) -> Self {
95        RealityError::Validation(e.to_string())
96    }
97}