lighthouse_client/
error.rs

1use async_tungstenite::tungstenite;
2use lighthouse_protocol::ValueError;
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
6
7/// The type for any error involved in communication with the lighthouse.
8#[derive(Debug, Error)]
9pub enum Error {
10    #[error("Tungstenite (WebSocket) error: {0}")]
11    Tungstenite(#[from] tungstenite::Error),
12    #[error("MessagePack encoding error: {0}")]
13    Encode(#[from] rmp_serde::encode::Error),
14    #[error("MessagePack decoding error: {0}")]
15    Decode(#[from] rmp_serde::decode::Error),
16    #[error("MessagePack value error: {0}")]
17    Value(#[from] ValueError),
18    #[error("Server error: {} {} (warnings: {:?})", code, message.clone().unwrap_or_else(|| "(no message)".to_string()), warnings)]
19    Server { code: i32, message: Option<String>, warnings: Vec<String> },
20    #[error("No next message available")]
21    NoNextMessage,
22    #[error("The connection was closed")]
23    ConnectionClosed,
24    #[error("Custom error")]
25    Custom(String),
26}
27
28impl Error {
29    /// Creates a new `LighthouseError` from the given custom message.
30    pub fn custom(s: &str) -> Self { Self::Custom(s.to_owned()) }
31}