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)
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.