rustywallet_electrum/
error.rs

1//! Error types for Electrum client operations.
2
3use thiserror::Error;
4
5/// Errors that can occur during Electrum client operations.
6#[derive(Debug, Error)]
7pub enum ElectrumError {
8    /// Failed to connect to server
9    #[error("Connection failed: {0}")]
10    ConnectionFailed(String),
11
12    /// Connection timeout
13    #[error("Connection timeout")]
14    Timeout,
15
16    /// Server returned an error
17    #[error("Server error ({code}): {message}")]
18    ServerError {
19        /// Error code from server
20        code: i32,
21        /// Error message from server
22        message: String,
23    },
24
25    /// Invalid Bitcoin address
26    #[error("Invalid address: {0}")]
27    InvalidAddress(String),
28
29    /// Invalid response from server
30    #[error("Invalid response: {0}")]
31    InvalidResponse(String),
32
33    /// TLS/SSL error
34    #[error("TLS error: {0}")]
35    TlsError(String),
36
37    /// I/O error
38    #[error("I/O error: {0}")]
39    IoError(#[from] std::io::Error),
40
41    /// JSON parsing error
42    #[error("JSON error: {0}")]
43    JsonError(#[from] serde_json::Error),
44
45    /// Request ID mismatch
46    #[error("Request ID mismatch: expected {expected}, got {got}")]
47    IdMismatch {
48        /// Expected request ID
49        expected: u64,
50        /// Received request ID
51        got: u64,
52    },
53
54    /// Server disconnected
55    #[error("Server disconnected")]
56    Disconnected,
57
58    /// Invalid scripthash
59    #[error("Invalid scripthash: {0}")]
60    InvalidScripthash(String),
61
62    /// Certificate pinning failed
63    #[error("Certificate pinning failed: {0}")]
64    CertificatePinningFailed(String),
65
66    /// No servers available
67    #[error("No servers available")]
68    NoServersAvailable,
69
70    /// Pool exhausted
71    #[error("Connection pool exhausted")]
72    PoolExhausted,
73
74    /// Subscription error
75    #[error("Subscription error: {0}")]
76    SubscriptionError(String),
77}
78
79/// Result type alias for Electrum operations.
80pub type Result<T> = std::result::Result<T, ElectrumError>;