Skip to main content

seedlink_rs_client/
error.rs

1use std::time::Duration;
2
3/// Errors that can occur during SeedLink client operations.
4#[derive(Debug, thiserror::Error)]
5pub enum ClientError {
6    /// TCP or socket I/O error.
7    #[error("I/O error: {0}")]
8    Io(#[from] std::io::Error),
9
10    /// SeedLink protocol parsing error (invalid frame, bad command format, etc.).
11    #[error("protocol error: {0}")]
12    Protocol(#[from] seedlink_rs_protocol::SeedlinkError),
13
14    /// Operation exceeded the configured timeout duration.
15    #[error("timeout after {0:?}")]
16    Timeout(Duration),
17
18    /// Server closed the connection (read returned 0 bytes).
19    #[error("disconnected")]
20    Disconnected,
21
22    /// Server returned an ERROR response to a command.
23    #[error("server error: {0}")]
24    ServerError(String),
25
26    /// Method called in wrong client state (e.g., `next_frame` before `end_stream`).
27    #[error("invalid state: expected {expected}, actual {actual}")]
28    InvalidState {
29        /// The state(s) required for the operation.
30        expected: &'static str,
31        /// The current client state.
32        actual: &'static str,
33    },
34
35    /// Protocol version negotiation failed.
36    #[error("negotiation failed: {0}")]
37    NegotiationFailed(String),
38
39    /// Server sent an unexpected response line.
40    #[error("unexpected response: {0}")]
41    UnexpectedResponse(String),
42
43    /// Auto-reconnect exhausted all retry attempts.
44    #[error("reconnect failed after {attempts} attempts")]
45    ReconnectFailed {
46        /// Number of reconnect attempts made.
47        attempts: u32,
48    },
49}
50
51/// Convenience alias for `Result<T, ClientError>`.
52pub type Result<T> = std::result::Result<T, ClientError>;