1use thiserror::Error;
2
3use crate::varint::FeedVarintDecoderError;
4
5#[derive(Debug, Error)]
8pub enum ReadFrameError {
9 #[error(transparent)]
10 IO(#[from] std::io::Error),
11
12 #[error("failed to decode frame length")]
13 FailedToDecodeFrameLength(
14 #[from]
15 #[source]
16 FeedVarintDecoderError,
17 ),
18}
19
20#[cfg(feature = "typed")]
23#[derive(Debug, Error)]
24pub enum ReadFrameTypedError {
25 #[error("failed to read frame")]
26 FailedToReadFrame(
27 #[from]
28 #[source]
29 ReadFrameError,
30 ),
31
32 #[error("failed to deserialize frame")]
33 FailedToDeserializeFrame(
34 #[from]
35 #[source]
36 bincode::Error,
37 ),
38}
39
40#[derive(Debug, Error)]
43pub enum WriteFrameError {
44 #[error(transparent)]
45 IO(#[from] std::io::Error),
46
47 #[error(
48 "frame with length {length} is too long, max allowed frame length is {max_allowed_frame_length}"
49 )]
50 FrameTooLong {
51 length: usize,
52 max_allowed_frame_length: usize,
53 },
54}
55
56#[cfg(feature = "typed")]
59#[derive(Debug, Error)]
60pub enum WriteFrameTypedError {
61 #[error("failed to write frame")]
62 FailedToWriteFrame(
63 #[from]
64 #[source]
65 WriteFrameError,
66 ),
67
68 #[error("failed to serialize frame")]
69 FailedToSerializeFrame(
70 #[from]
71 #[source]
72 bincode::Error,
73 ),
74}
75
76#[cfg(feature = "typed")]
77impl From<std::io::Error> for WriteFrameTypedError {
78 fn from(err: std::io::Error) -> Self {
79 Self::FailedToWriteFrame(err.into())
80 }
81}