Skip to main content

websock_proto/
error.rs

1use thiserror::Error;
2
3/// Result type for protocol and transport operations.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Errors that can occur when sending or receiving WebSocket messages.
7#[derive(Debug, Error)]
8pub enum Error {
9    /// The connection has been closed.
10    #[error("connection closed")]
11    Closed,
12
13    /// The provided URL was not valid.
14    #[error("invalid url: {0}")]
15    InvalidUrl(String),
16
17    /// A protocol violation or malformed message was encountered.
18    #[error("protocol error: {0}")]
19    Protocol(String),
20
21    /// An IO failure occurred while reading or writing.
22    #[error("io error: {0}")]
23    Io(String),
24
25    /// A TLS handshake or validation error occurred.
26    #[error("tls error: {0}")]
27    Tls(String),
28
29    /// The operation is not supported on the current platform or configuration.
30    #[error("unsupported: {0}")]
31    Unsupported(String),
32
33    #[error("frame decode error: {0}")]
34    FrameDecode(String),
35
36    #[error("stream id error: {0}")]
37    StreamId(String),
38
39    /// A catch-all error for unexpected failures.
40    #[error("other error: {0}")]
41    Other(String),
42}
43
44impl Error {
45    /// Create an `Error::Other` from any displayable error value.
46    pub fn other<E: std::fmt::Display>(e: E) -> Self {
47        Self::Other(e.to_string())
48    }
49}