kimberlite_client/
error.rs1use kimberlite_wire::{ErrorCode, WireError};
4use thiserror::Error;
5
6pub type ClientResult<T> = Result<T, ClientError>;
8
9#[derive(Debug, Error)]
11pub enum ClientError {
12 #[error("connection error: {0}")]
14 Connection(#[from] std::io::Error),
15
16 #[error("wire protocol error: {0}")]
18 Wire(#[from] WireError),
19
20 #[error("server error ({code:?}): {message}")]
22 Server { code: ErrorCode, message: String },
23
24 #[error("not connected to server")]
26 NotConnected,
27
28 #[error("response ID {received} does not match request ID {expected}")]
30 ResponseMismatch { expected: u64, received: u64 },
31
32 #[error("unexpected response type: expected {expected}, got {actual}")]
34 UnexpectedResponse { expected: String, actual: String },
35
36 #[error("connection timeout")]
38 Timeout,
39
40 #[error("handshake failed: {0}")]
42 HandshakeFailed(String),
43}
44
45impl ClientError {
46 pub fn server(code: ErrorCode, message: impl Into<String>) -> Self {
48 Self::Server {
49 code,
50 message: message.into(),
51 }
52 }
53}