1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crate::frame::Frame;
use std::io;
use std::string::FromUtf8Error;
use thiserror::Error;
use tokio::sync::mpsc::error::SendError;
use tokio::time::error::Elapsed;
use url::ParseError;

#[derive(Error, Debug)]
pub enum Error {
    // Sender / Receiver Errors
    #[error("{source}")]
    SendError {
        #[from]
        source: SendError<Frame>,
    },

    #[error("channel communication error")]
    CommunicationError,

    // General Errors
    #[error("{source}")]
    Timeout {
        #[from]
        source: Elapsed,
    },

    #[error("IO Error happened: {source}")]
    IOError {
        #[from]
        source: io::Error,
    },

    #[error("{source}")]
    FromUtf8Error {
        #[from]
        source: FromUtf8Error,
    },

    // Handshake Errors
    #[error("Couldn't find Sec-WebSocket-Key header in the request")]
    NoSecWebsocketKey,

    #[error("Server didn't upgrade the connection")]
    NoUpgrade,

    #[error("Sever didn't send a valid Sec-WebSocket-Accept key")]
    InvalidAcceptKey,

    // Framing Errors
    #[error("RSV not zero")]
    RSVNotZero,

    #[error("Control frames must not be fragmented")]
    ControlFramesFragmented,

    #[error("Control frame with invalid payload size, can be greater than 125")]
    ControlFramePayloadSize,

    #[error("Payload too large")]
    PayloadSize,

    // Fragmentation Errors
    #[error("Invalid frame while there is a fragmented message in progress")]
    InvalidFrameFragmentation,

    #[error("Incoming fragmented message but there is one already in progress")]
    FragmentedInProgress,

    #[error("Invalid continuation frame: no fragmented message to continue")]
    InvalidContinuationFrame,

    #[error("Invalid Opcode")]
    InvalidOpcode,

    // HTTP Errors
    #[error("{source}")]
    URLParseError {
        #[from]
        source: ParseError,
    },

    #[error("Invalid scheme in WebSocket URL")]
    InvalidSchemeURL,

    #[error("URL has no host")]
    URLNoHost,

    #[error("URL has no port")]
    URLNoPort,
}