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 /// A generic, miscellaneous error carrying a descriptive message.
11 #[error("{0}")]
12 Other(String),
13
14 /// The server failed to bind and listen on the requested address.
15 #[error("{0}")]
16 Listen(String),
17
18 /// Indicates that no messages have been received
19 /// within the specified timeout period
20 #[error("Connection timeout")]
21 ConnectionTimeout,
22
23 /// Indicates that the data received is not a
24 /// valid handshake message
25 #[error("Malformed handshake message")]
26 MalformedHandshake,
27
28 /// Indicates that the data received is not a
29 /// valid or acceptable message
30 #[error("Malformed handshake message")]
31 MalformedMessage,
32
33 /// Indicates handler negotiation failure
34 /// This error code is reserved for structs
35 /// implementing WebSocket handler.
36 #[error("Negotiation failure")]
37 NegotiationFailure,
38
39 /// Indicates handler negotiation failure
40 /// with a specific reason
41 /// This error code is reserved for structs
42 /// implementing WebSocket handler.
43 #[error("Negotiation failure: {0}")]
44 NegotiationFailureWithReason(String),
45
46 /// Error sending response via the
47 /// tokio MPSC response channel
48 #[error("Response channel send error {0:?}")]
49 ResponseChannelError(#[from] SendError<tungstenite::Message>),
50
51 /// WebSocket error produced by the underlying
52 /// Tungstenite WebSocket crate
53 #[error("WebSocket error: {0}")]
54 WebSocketError(Box<tungstenite::Error>),
55
56 /// Connection terminated abnormally
57 #[error("Connection closed abnormally")]
58 AbnormalClose,
59
60 /// Server closed connection
61 #[error("Server closed connection")]
62 ServerClose,
63
64 /// Failure while signaling the listener to stop.
65 #[error("Error signaling listener shutdown: {0}")]
66 Stop(String),
67
68 /// Failure while signaling that the listener has finished shutting down.
69 #[error("Error signaling listener shutdown: {0}")]
70 Done(String),
71
72 /// Failure while waiting for the listener to shut down.
73 #[error("Error waiting for listener shutdown: {0}")]
74 Join(String),
75
76 /// An underlying I/O error.
77 #[error(transparent)]
78 IoError(#[from] std::io::Error),
79}
80
81impl From<String> for Error {
82 fn from(value: String) -> Self {
83 Error::Other(value)
84 }
85}
86
87impl From<tungstenite::Error> for Error {
88 fn from(value: tungstenite::Error) -> Self {
89 Error::WebSocketError(Box::new(value))
90 }
91}