reth_node_ethstats/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during `WebSocket` connection handling
4#[derive(Debug, Error)]
5pub enum ConnectionError {
6    /// The `WebSocket` connection was closed unexpectedly
7    #[error("Connection closed")]
8    ConnectionClosed,
9
10    /// Error occurred during JSON serialization/deserialization
11    #[error("Serialization error: {0}")]
12    Serialization(#[from] serde_json::Error),
13
14    /// Error occurred during `WebSocket` communication
15    #[error("WebSocket error: {0}")]
16    WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
17}
18
19/// Main error type for the `EthStats` client
20///
21/// This enum covers all possible errors that can occur when interacting
22/// with an `EthStats` server, including connection issues, authentication
23/// problems, data fetching errors, and various I/O operations.
24#[derive(Debug, Error)]
25pub enum EthStatsError {
26    /// The provided URL is invalid or malformed
27    #[error("Invalid URL: {0}")]
28    InvalidUrl(String),
29
30    /// Error occurred during connection establishment or maintenance
31    #[error("Connection error: {0}")]
32    ConnectionError(#[from] ConnectionError),
33
34    /// Authentication failed with the `EthStats` server
35    #[error("Authentication error: {0}")]
36    AuthError(String),
37
38    /// Attempted to perform an operation while not connected to the server
39    #[error("Not connected to server")]
40    NotConnected,
41
42    /// Error occurred during JSON serialization or deserialization
43    #[error("Serialization error: {0}")]
44    Serialization(#[from] serde_json::Error),
45
46    /// Error occurred during `WebSocket` communication
47    #[error("WebSocket error: {0}")]
48    WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
49
50    /// Operation timed out
51    #[error("Timeout error")]
52    Timeout,
53
54    /// Error occurred while parsing a URL
55    #[error("URL parsing error: {0}")]
56    Url(#[from] url::ParseError),
57
58    /// Requested block was not found in the blockchain
59    #[error("Block not found: {0}")]
60    BlockNotFound(u64),
61
62    /// Error occurred while fetching data from the blockchain or server
63    #[error("Data fetch error: {0}")]
64    DataFetchError(String),
65
66    /// The request sent to the server was invalid or malformed
67    #[error("Inivalid request")]
68    InvalidRequest,
69}