Skip to main content

ogmios_client/
error.rs

1//! Error types for the Ogmios client.
2
3use thiserror::Error;
4
5/// Main error type for the Ogmios client.
6#[derive(Error, Debug)]
7pub enum OgmiosError {
8    /// WebSocket connection error
9    #[error("WebSocket error: {0}")]
10    WebSocket(String),
11
12    /// HTTP handshake error
13    #[error("HTTP handshake error: {0}")]
14    HttpHandshake(String),
15
16    /// HTTP request error (for health checks)
17    #[error("HTTP error: {0}")]
18    Http(#[from] reqwest::Error),
19
20    /// JSON serialization/deserialization error
21    #[error("JSON error: {0}")]
22    Json(#[from] serde_json::Error),
23
24    /// Server not ready error
25    #[error("Server not ready: network synchronization is {synchronization:.2}%, minimum required is {minimum:.2}%")]
26    ServerNotReady {
27        /// Server health network synchronization
28        synchronization: f64,
29        /// Synchronization minimum required
30        minimum: f64,
31    },
32
33    /// Connection closed unexpectedly
34    #[error("Connection closed unexpectedly")]
35    ConnectionClosed,
36
37    /// Socket not open
38    #[error("Socket is not open (state: {state})")]
39    SocketNotOpen {
40        /// Socket state
41        state: String,
42    },
43
44    /// Invalid response from server
45    #[error("Invalid response from server: {message}")]
46    InvalidResponse {
47        /// Error message
48        message: String,
49    },
50
51    /// Request timeout
52    #[error("Request timed out after {timeout_ms}ms")]
53    Timeout {
54        /// Timedout after (ms) value
55        timeout_ms: u64,
56    },
57
58    /// Intersection not found during chain sync
59    #[error("Intersection not found: {tip:?}")]
60    IntersectionNotFound {
61        /// Tip Or Origin, check the field Tip (object) and Origin (string) for more information
62        tip: Option<String>,
63    },
64
65    /// Transaction submission error
66    #[error("Transaction submission failed: {0}")]
67    SubmissionError(String),
68
69    /// Transaction evaluation error
70    #[error("Transaction evaluation failed: {0}")]
71    EvaluationError(String),
72
73    /// Ledger state acquisition error
74    #[error("Failed to acquire ledger state: {0}")]
75    AcquisitionError(String),
76
77    /// Query error
78    #[error("Query failed: {0}")]
79    QueryError(String),
80
81    /// URL parsing error
82    #[error("URL parsing error: {0}")]
83    UrlParse(#[from] url::ParseError),
84
85    /// Generic I/O error
86    #[error("I/O error: {0}")]
87    Io(#[from] std::io::Error),
88
89    /// Channel send error
90    #[error("Channel send error: {0}")]
91    ChannelSend(String),
92
93    /// Channel receive error
94    #[error("Channel receive error: receiver dropped")]
95    ChannelRecv,
96}
97
98/// Result type alias for Ogmios operations.
99pub type Result<T> = std::result::Result<T, OgmiosError>;