Skip to main content

grip_control/
error.rs

1use std::{
2    error::Error,
3    fmt::{self, Display},
4};
5
6#[derive(Debug)]
7pub enum WebsocketEventError {
8    UnrecognizedCommand,
9    ParseError,
10    InvalidLength,
11    InvalidUtf8,
12    TruncatedBody,
13    MissingTrailingCrlf,
14    MissingLength,
15}
16
17impl Display for WebsocketEventError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            WebsocketEventError::ParseError => write!(f, "failed to parse websocket event"),
21            WebsocketEventError::UnrecognizedCommand => {
22                write!(f, "failed to parse websocket command")
23            }
24            WebsocketEventError::InvalidLength => write!(f, "websocket frame was invalid length"),
25            WebsocketEventError::InvalidUtf8 => write!(f, "websocket frame was invalid utf8"),
26            WebsocketEventError::TruncatedBody => write!(f, "websocket frame has a truncated body"),
27            WebsocketEventError::MissingTrailingCrlf => write!(
28                f,
29                "websocket frame has a truncated is missing trailing crlf"
30            ),
31            WebsocketEventError::MissingLength => write!(f, "websocket frame was missing length"),
32        }
33    }
34}
35
36impl Error for WebsocketEventError {}