Enum WebSocketError

Source
pub enum WebSocketError {
Show 23 variants InvalidFragment, InvalidUTF8, InvalidContinuationFrame, InvalidStatusCode(u16), InvalidUpgradeHeader, InvalidConnectionHeader, ConnectionClosed, InvalidCloseFrame, InvalidCloseCode, ReservedBitsNotZero, ControlFrameFragmented, PingFrameTooLarge, FrameTooLarge, InvalidSecWebsocketVersion, InvalidOpCode(u8), MissingSecWebSocketKey, InvalidHttpScheme, CompressionNotSupported, UrlParseError(ParseError), IoError(Error), HTTPError(Error), Reqwest(Error), Json(Error),
}
Expand description

Represents errors that can occur during WebSocket operations.

This enum encompasses all possible error conditions that may arise when working with WebSocket connections, including protocol violations, connection issues, and data validation errors. The errors are broadly categorized into:

  • Protocol errors (e.g., invalid frames, incorrect sequence of operations)
  • Data validation errors (e.g., invalid UTF-8, oversized payloads)
  • HTTP/Connection errors (e.g., header issues, connection closure)
  • I/O and system-level errors

Each variant includes detailed documentation about the specific error condition and when it might occur.

Variants§

§

InvalidFragment

Occurs when receiving a WebSocket fragment that violates the protocol specification, such as receiving a new fragment before completing the previous one.

§

InvalidUTF8

Indicates that a text frame or close frame reason contains invalid UTF-8 data. According to RFC 6455, all text payloads must be valid UTF-8.

§

InvalidContinuationFrame

Occurs when receiving a continuation frame without a preceding initial frame, or when the continuation sequence is otherwise invalid according to RFC 6455.

§

InvalidStatusCode(u16)

Returned when receiving an HTTP status code that is not valid for WebSocket handshake. Only certain status codes (like 101 for successful upgrade) are valid.

§

InvalidUpgradeHeader

Indicates that the HTTP “Upgrade” header is either missing or does not contain the required “websocket” value during connection handshake.

§

InvalidConnectionHeader

Indicates that the HTTP “Connection” header is either missing or does not contain the required “upgrade” value during connection handshake.

§

ConnectionClosed

Returned when attempting to perform operations on a closed WebSocket connection. Once a connection is closed, no further communication is possible.

§

InvalidCloseFrame

Indicates that a received close frame has an invalid format, such as containing a payload of 1 byte (close frames must be either empty or ≥2 bytes).

§

InvalidCloseCode

Occurs when a close frame contains a status code that is not valid according to RFC 6455 (e.g., using reserved codes or codes in invalid ranges).

§

ReservedBitsNotZero

Indicates that reserved bits in the WebSocket frame header are set when they should be 0 according to the protocol specification.

§

ControlFrameFragmented

Occurs when a control frame (ping, pong, or close) is received with the FIN bit not set. RFC 6455 requires that control frames must not be fragmented.

§

PingFrameTooLarge

Indicates that a received ping frame exceeds the maximum allowed size of 125 bytes as specified in RFC 6455.

§

FrameTooLarge

Occurs when a received frame’s payload length exceeds the maximum configured size. This helps prevent memory exhaustion attacks.

§

InvalidSecWebsocketVersion

Returned when the “Sec-WebSocket-Version” header is not set to 13 during handshake. RFC 6455 requires version 13 for modern WebSocket connections.

§

InvalidOpCode(u8)

Indicates receipt of a frame with an invalid opcode value. RFC 6455 defines a specific set of valid opcodes (0x0 through 0xF).

§

MissingSecWebSocketKey

Occurs during handshake when the required “Sec-WebSocket-Key” header is missing from the client request.

§

InvalidHttpScheme

Returned when attempting to establish a WebSocket connection with an invalid URL scheme. Only “ws://” and “wss://” schemes are valid.

§

CompressionNotSupported

Occurs when receiving a compressed frame on a connection where compression was not negotiated during the handshake.

§

UrlParseError(ParseError)

Wraps errors from URL parsing that may occur when processing WebSocket URLs.

§

IoError(Error)

Wraps standard I/O errors that may occur during WebSocket communication, such as connection resets or network timeouts.

§

HTTPError(Error)

Wraps errors from the hyper HTTP library that may occur during the WebSocket handshake process or connection upgrade.

§

Reqwest(Error)

Available on crate feature reqwest only.

Wraps errors from the reqwest client library that may occur when using reqwest for WebSocket connections.

§

Json(Error)

Occurs when serialization of JSON data fails. Only available when the json feature is enabled.

Trait Implementations§

Source§

impl Debug for WebSocketError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for WebSocketError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for WebSocketError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for WebSocketError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for WebSocketError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for WebSocketError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for WebSocketError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for WebSocketError

Source§

fn from(source: ParseError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T