tokio_websockets/proto/
error.rs1use std::fmt;
3
4#[allow(clippy::module_name_repetitions)]
6#[derive(Debug)]
7#[non_exhaustive]
8pub enum ProtocolError {
9 FragmentedControlFrame,
11 InvalidCloseCode,
13 InvalidOpcode,
15 InvalidPayloadLength,
17 InvalidRsv,
20 InvalidUtf8,
22 UnexpectedMaskedFrame,
24 UnexpectedUnmaskedFrame,
26}
27
28impl ProtocolError {
29 pub(super) const fn as_str(&self) -> &'static str {
31 match self {
32 ProtocolError::FragmentedControlFrame => "fragmented control frame",
33 ProtocolError::InvalidCloseCode => "invalid close code",
34 ProtocolError::InvalidOpcode => "invalid opcode",
35 ProtocolError::InvalidPayloadLength => "invalid payload length",
36 ProtocolError::InvalidRsv => "invalid extension",
37 ProtocolError::InvalidUtf8 => "invalid utf-8",
38 ProtocolError::UnexpectedMaskedFrame => "unexpected masked frame",
39 ProtocolError::UnexpectedUnmaskedFrame => "unexpected unmasked frame",
40 }
41 }
42}
43
44impl fmt::Display for ProtocolError {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 f.write_str(self.as_str())
47 }
48}
49
50impl std::error::Error for ProtocolError {}