Skip to main content

elara_core/
error.rs

1//! Error types for ELARA protocol
2
3use thiserror::Error;
4
5use crate::{EventId, NodeId, StateId};
6
7/// Core ELARA errors
8#[derive(Error, Debug)]
9pub enum ElaraError {
10    // Wire errors
11    #[error("Invalid wire format: {0}")]
12    InvalidWireFormat(String),
13
14    #[error("Buffer too short: expected {expected}, got {actual}")]
15    BufferTooShort { expected: usize, actual: usize },
16
17    #[error("Unknown packet class: {0}")]
18    UnknownPacketClass(u8),
19
20    #[error("Unknown event type: {0}")]
21    UnknownEventType(u8),
22
23    // Crypto errors
24    #[error("Decryption failed")]
25    DecryptionFailed,
26
27    #[error("Invalid signature")]
28    InvalidSignature,
29
30    #[error("Replay detected: seq {0}")]
31    ReplayDetected(u32),
32
33    #[error("Ratchet out of sync")]
34    RatchetOutOfSync,
35
36    // Authority errors
37    #[error("Unauthorized: node {node} cannot mutate state {state}")]
38    Unauthorized { node: NodeId, state: StateId },
39
40    #[error("Authority revoked for node {0}")]
41    AuthorityRevoked(NodeId),
42
43    // Causality errors
44    #[error("Causality violation")]
45    CausalityViolation,
46
47    #[error("Missing dependency: {0:?}")]
48    MissingDependency(EventId),
49
50    // State errors
51    #[error("State not found: {0:?}")]
52    StateNotFound(StateId),
53
54    #[error("State bounds exceeded")]
55    StateBoundsExceeded,
56
57    #[error("Rate limit exceeded")]
58    RateLimitExceeded,
59
60    #[error("Entropy exceeded")]
61    EntropyExceeded,
62
63    // Time errors
64    #[error("Event too late: beyond correction horizon")]
65    EventTooLate,
66
67    #[error("Event too early: beyond prediction horizon")]
68    EventTooEarly,
69
70    // Session errors
71    #[error("Session not found")]
72    SessionNotFound,
73
74    #[error("Session mismatch")]
75    SessionMismatch,
76
77    #[error("Node not in session")]
78    NodeNotInSession,
79
80    // Transport errors
81    #[error("Transport error: {0}")]
82    TransportError(String),
83
84    #[error("Connection failed")]
85    ConnectionFailed,
86}
87
88/// Result type for ELARA operations
89pub type ElaraResult<T> = Result<T, ElaraError>;