csv_adapter_core/
error.rs1use thiserror::Error;
4
5pub type Result<T> = core::result::Result<T, AdapterError>;
7
8#[derive(Error, Debug)]
10pub enum AdapterError {
11 #[error("Seal replay detected: seal {0:?}")]
13 SealReplay(String),
14
15 #[error("Invalid seal: {0}")]
17 InvalidSeal(String),
18
19 #[error("Commitment hash mismatch: expected {expected}, got {actual}")]
21 CommitmentMismatch {
22 expected: String,
24 actual: String,
26 },
27
28 #[error("Inclusion proof failed: {0}")]
30 InclusionProofFailed(String),
31
32 #[error("Finality not reached: {0}")]
34 FinalityNotReached(String),
35
36 #[error("Anchor invalidated by reorg: {0:?}")]
38 ReorgInvalid(String),
39
40 #[error("Network error: {0}")]
42 NetworkError(String),
43
44 #[error("Publish failed: {0}")]
46 PublishFailed(String),
47
48 #[error("Serialization error: {0}")]
50 SerializationError(String),
51
52 #[error("Invalid configuration: {0}")]
54 InvalidConfig(String),
55
56 #[error("Version mismatch: expected {expected}, got {actual}")]
58 VersionMismatch {
59 expected: u8,
61 actual: u8,
63 },
64
65 #[error("Domain separator mismatch")]
67 DomainSeparatorMismatch,
68
69 #[error("Signature verification failed: {0}")]
71 SignatureVerificationFailed(String),
72
73 #[error("Adapter error: {0}")]
75 Generic(String),
76}
77
78impl AdapterError {
79 pub fn is_reorg(&self) -> bool {
81 matches!(self, AdapterError::ReorgInvalid(_))
82 }
83
84 pub fn is_replay(&self) -> bool {
86 matches!(self, AdapterError::SealReplay(_))
87 }
88
89 pub fn is_signature_error(&self) -> bool {
91 matches!(self, AdapterError::SignatureVerificationFailed(_))
92 }
93}
94
95#[cfg(test)]
96mod tests {
97 use super::*;
98
99 #[test]
100 fn test_error_display() {
101 let err = AdapterError::SealReplay("abc123".to_string());
102 assert!(err.to_string().contains("replay"));
103 }
104
105 #[test]
106 fn test_error_is_reorg() {
107 let err = AdapterError::ReorgInvalid("anchor".to_string());
108 assert!(err.is_reorg());
109 }
110
111 #[test]
112 fn test_error_is_replay() {
113 let err = AdapterError::SealReplay("seal".to_string());
114 assert!(err.is_replay());
115 }
116
117 #[test]
118 fn test_error_is_signature_error() {
119 let err = AdapterError::SignatureVerificationFailed("invalid sig".to_string());
120 assert!(err.is_signature_error());
121 }
122
123 #[test]
124 fn test_error_signature_verification_failed() {
125 let err = AdapterError::SignatureVerificationFailed("bad signature".to_string());
126 assert!(err.to_string().contains("Signature verification failed"));
127 }
128}