1use thiserror::Error;
4
5use crate::{EventId, NodeId, StateId};
6
7#[derive(Error, Debug)]
9pub enum ElaraError {
10 #[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 #[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 #[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 #[error("Causality violation")]
45 CausalityViolation,
46
47 #[error("Missing dependency: {0:?}")]
48 MissingDependency(EventId),
49
50 #[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 #[error("Event too late: beyond correction horizon")]
65 EventTooLate,
66
67 #[error("Event too early: beyond prediction horizon")]
68 EventTooEarly,
69
70 #[error("Session not found")]
72 SessionNotFound,
73
74 #[error("Session mismatch")]
75 SessionMismatch,
76
77 #[error("Node not in session")]
78 NodeNotInSession,
79
80 #[error("Transport error: {0}")]
82 TransportError(String),
83
84 #[error("Connection failed")]
85 ConnectionFailed,
86}
87
88pub type ElaraResult<T> = Result<T, ElaraError>;