Skip to main content

qcomm_core/
error.rs

1//! Error types for Quantum Communicator
2
3use thiserror::Error;
4
5/// Result type alias using our Error type
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur in Quantum Communicator
9#[derive(Debug, Error)]
10pub enum Error {
11    // Crypto errors
12    #[error("Key generation failed: {0}")]
13    KeyGeneration(String),
14
15    #[error("Encryption failed: {0}")]
16    Encryption(String),
17
18    #[error("Decryption failed: {0}")]
19    Decryption(String),
20
21    #[error("Invalid signature")]
22    InvalidSignature,
23
24    #[error("Signature creation failed: {0}")]
25    SignatureCreation(String),
26
27    #[error("Signature verification failed: {0}")]
28    SignatureVerification(String),
29
30    #[error("Key exchange failed: {0}")]
31    KeyExchange(String),
32
33    #[error("Ratchet state corrupted: {0}")]
34    RatchetCorrupted(String),
35
36    // QRNG errors
37    #[error("QRNG unavailable: {0}")]
38    QrngUnavailable(String),
39
40    #[error("Insufficient entropy")]
41    InsufficientEntropy,
42
43    // QKD errors
44    #[error("QKD channel not established")]
45    QkdNotEstablished,
46
47    #[error("QKD key exhausted")]
48    QkdKeyExhausted,
49
50    #[error("QKD connection failed: {0}")]
51    QkdConnection(String),
52
53    // Transport errors
54    #[error("BLE error: {0}")]
55    Ble(String),
56
57    #[error("Nostr error: {0}")]
58    Nostr(String),
59
60    #[error("Connection failed: {0}")]
61    Connection(String),
62
63    #[error("Timeout")]
64    Timeout,
65
66    // Protocol errors
67    #[error("Protocol version mismatch: expected {expected}, got {actual}")]
68    ProtocolMismatch { expected: u8, actual: u8 },
69
70    #[error("Invalid message format: {0}")]
71    InvalidMessage(String),
72
73    #[error("Unknown peer: {0}")]
74    UnknownPeer(String),
75
76    // Node errors
77    #[error("Node sync failed: {0}")]
78    NodeSync(String),
79
80    #[error("RPC error: {0}")]
81    Rpc(String),
82
83    #[error("Transaction failed: {0}")]
84    Transaction(String),
85
86    // AI errors
87    #[error("AI agent error: {0}")]
88    AiAgent(String),
89
90    // General errors
91    #[error("Configuration error: {0}")]
92    Config(String),
93
94    #[error("IO error: {0}")]
95    Io(#[from] std::io::Error),
96
97    #[error("Serialization error: {0}")]
98    Serialization(String),
99}