workflow_websocket/server/
error.rs

1//!
2//! [`enum@Error`] enum declaration for server-side WebSocket errors.
3//!
4use thiserror::Error;
5use tokio::sync::mpsc::error::SendError;
6
7/// Errors produced by the [`WebSocketServer`](super::WebSocketServer).
8#[derive(Debug, Error)]
9pub enum Error {
10    #[error("{0}")]
11    Other(String),
12
13    #[error("{0}")]
14    Listen(String),
15
16    /// Indicates that no messages have been received
17    /// within the specified timeout period
18    #[error("Connection timeout")]
19    ConnectionTimeout,
20
21    /// Indicates that the data received is not a
22    /// valid handshake message
23    #[error("Malformed handshake message")]
24    MalformedHandshake,
25
26    /// Indicates that the data received is not a
27    /// valid or acceptable message
28    #[error("Malformed handshake message")]
29    MalformedMessage,
30
31    /// Indicates handler negotiation failure
32    /// This error code is reserved for structs
33    /// implementing WebSocket handler.
34    #[error("Negotiation failure")]
35    NegotiationFailure,
36
37    /// Indicates handler negotiation failure
38    /// with a specific reason
39    /// This error code is reserved for structs
40    /// implementing WebSocket handler.
41    #[error("Negotiation failure: {0}")]
42    NegotiationFailureWithReason(String),
43
44    /// Error sending response via the
45    /// tokio MPSC response channel
46    #[error("Response channel send error {0:?}")]
47    ResponseChannelError(#[from] SendError<tungstenite::Message>),
48
49    /// WebSocket error produced by the underlying
50    /// Tungstenite WebSocket crate
51    #[error("WebSocket error: {0}")]
52    WebSocketError(#[from] tungstenite::Error),
53
54    /// Connection terminated abnormally
55    #[error("Connection closed abnormally")]
56    AbnormalClose,
57
58    /// Server closed connection
59    #[error("Server closed connection")]
60    ServerClose,
61
62    #[error("Error signaling listener shutdown: {0}")]
63    Stop(String),
64
65    #[error("Error signaling listener shutdown: {0}")]
66    Done(String),
67
68    #[error("Error waiting for listener shutdown: {0}")]
69    Join(String),
70
71    #[error(transparent)]
72    IoError(#[from] std::io::Error),
73}
74
75impl From<String> for Error {
76    fn from(value: String) -> Self {
77        Error::Other(value)
78    }
79}