1use std::io;
2
3use thiserror::Error;
4
5#[derive(Debug, Error, PartialEq)]
7pub enum Error {
8 #[error("The operation cannot be completed because the connection is in an invalid state.")]
10 InvalidState,
11
12 #[error("The operation cannot be completed because the stream({0}) is in an invalid state.")]
15 InvalidStreamState(u32),
16
17 #[error("The peer violated the local flow control limits.")]
19 FlowControl,
20
21 #[error("The specified stream({0}) was reset by the peer.")]
25 StreamReset(u32),
26
27 #[error("Call stream_send after setting the fin flag of the stream({0}).")]
29 FinalSize(u32),
30
31 #[error("There is no more work to do")]
32 Done,
33
34 #[error("The provided buffer is too short. expected {0}")]
36 BufferTooShort(u32),
37
38 #[error("The length of the frame received was too long to handle.")]
40 Overflow,
41
42 #[error("The provided packet cannot be parsed because its version is unknown({0}).")]
46 UnknownVersion(u8),
47
48 #[error("The provide frame can't be parsed,{0:?}")]
52 InvalidFrame(InvalidFrameKind),
53
54 #[error("Building frame violate the restrictions. {0:?}")]
58 FrameRestriction(FrameRestrictionKind),
59}
60
61#[derive(Debug, Clone, Copy, Error, PartialEq)]
63pub enum InvalidFrameKind {
64 #[error("Invalid frame type.")]
65 FrameType,
66
67 #[error("The Frame Flags field contains invalid flags.")]
68 Flags,
69 #[error("Data frame with empty body or Non data frame with non-empty body.")]
70 Body,
71 #[error("The GO_AWAY_FRAME and PING_FRAME should always use 0 StreamID, while other types of frames should not.")]
72 SessionId,
73}
74
75#[derive(Debug, Clone, Copy, Error, PartialEq)]
77pub enum FrameRestrictionKind {
78 #[error("Only DATA_FRAME is allowed to set the body content.")]
80 Body,
81 #[error("Set the invalid frame flags, see `create_without_body` for more information.")]
83 Flags,
84 #[error("The GO_AWAY_FRAME and PING_FRAME should always use 0 StreamID, while other types of frames should not.")]
86 SessionId,
87}
88
89pub type Result<T> = std::result::Result<T, Error>;
91
92impl From<Error> for io::Error {
93 fn from(value: Error) -> Self {
94 io::Error::new(io::ErrorKind::Other, value.to_string())
95 }
96}