1use crate::frame::FrameDecodeError;
12
13#[non_exhaustive]
15#[derive(Debug)]
16pub enum ConnectionError {
17 Io(std::io::Error),
19 Decode(FrameDecodeError),
21 NoMoreStreamIds,
23 Closed,
25 TooManyStreams,
27}
28
29impl std::fmt::Display for ConnectionError {
30 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
31 match self {
32 ConnectionError::Io(e) => write!(f, "i/o error: {e}"),
33 ConnectionError::Decode(e) => write!(f, "decode error: {e}"),
34 ConnectionError::NoMoreStreamIds => {
35 f.write_str("number of stream ids has been exhausted")
36 }
37 ConnectionError::Closed => f.write_str("connection is closed"),
38 ConnectionError::TooManyStreams => f.write_str("maximum number of streams reached"),
39 }
40 }
41}
42
43impl std::error::Error for ConnectionError {
44 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
45 match self {
46 ConnectionError::Io(e) => Some(e),
47 ConnectionError::Decode(e) => Some(e),
48 ConnectionError::NoMoreStreamIds
49 | ConnectionError::Closed
50 | ConnectionError::TooManyStreams => None,
51 }
52 }
53}
54
55impl From<std::io::Error> for ConnectionError {
56 fn from(e: std::io::Error) -> Self {
57 ConnectionError::Io(e)
58 }
59}
60
61impl From<FrameDecodeError> for ConnectionError {
62 fn from(e: FrameDecodeError) -> Self {
63 ConnectionError::Decode(e)
64 }
65}
66
67impl From<futures::channel::mpsc::SendError> for ConnectionError {
68 fn from(_: futures::channel::mpsc::SendError) -> Self {
69 ConnectionError::Closed
70 }
71}
72
73impl From<futures::channel::oneshot::Canceled> for ConnectionError {
74 fn from(_: futures::channel::oneshot::Canceled) -> Self {
75 ConnectionError::Closed
76 }
77}