xref: /xiu/protocol/rtsp/src/session/errors.rs (revision a4ef5d6c)
1 use {
2     crate::rtp::errors::{PackerError, UnPackerError},
3     bytesio::bytes_errors::BytesReadError,
4     bytesio::{bytes_errors::BytesWriteError, bytesio_errors::BytesIOError},
5     failure::{Backtrace, Fail},
6     std::fmt,
7     std::str::Utf8Error,
8     streamhub::errors::ChannelError,
9     tokio::sync::oneshot::error::RecvError,
10 };
11 
12 #[derive(Debug)]
13 pub struct SessionError {
14     pub value: SessionErrorValue,
15 }
16 
17 #[derive(Debug, Fail)]
18 pub enum SessionErrorValue {
19     #[fail(display = "net io error: {}", _0)]
20     BytesIOError(#[cause] BytesIOError),
21     #[fail(display = "bytes read error: {}", _0)]
22     BytesReadError(#[cause] BytesReadError),
23     #[fail(display = "bytes write error: {}", _0)]
24     BytesWriteError(#[cause] BytesWriteError),
25     #[fail(display = "Utf8Error: {}", _0)]
26     Utf8Error(#[cause] Utf8Error),
27     #[fail(display = "UnPackerError: {}", _0)]
28     UnPackerError(#[cause] UnPackerError),
29     #[fail(display = "stream hub event send error")]
30     StreamHubEventSendErr,
31     #[fail(display = "cannot receive frame data from stream hub")]
32     CannotReceiveFrameData,
33     #[fail(display = "pack error: {}", _0)]
34     PackerError(#[cause] PackerError),
35     #[fail(display = "event execute error: {}", _0)]
36     ChannelError(#[cause] ChannelError),
37     #[fail(display = "tokio: oneshot receiver err: {}", _0)]
38     RecvError(#[cause] RecvError),
39     #[fail(display = "Channel receive error")]
40     ChannelRecvError,
41 }
42 
43 impl From<BytesIOError> for SessionError {
from(error: BytesIOError) -> Self44     fn from(error: BytesIOError) -> Self {
45         SessionError {
46             value: SessionErrorValue::BytesIOError(error),
47         }
48     }
49 }
50 
51 impl From<BytesReadError> for SessionError {
from(error: BytesReadError) -> Self52     fn from(error: BytesReadError) -> Self {
53         SessionError {
54             value: SessionErrorValue::BytesReadError(error),
55         }
56     }
57 }
58 
59 impl From<BytesWriteError> for SessionError {
from(error: BytesWriteError) -> Self60     fn from(error: BytesWriteError) -> Self {
61         SessionError {
62             value: SessionErrorValue::BytesWriteError(error),
63         }
64     }
65 }
66 
67 impl From<Utf8Error> for SessionError {
from(error: Utf8Error) -> Self68     fn from(error: Utf8Error) -> Self {
69         SessionError {
70             value: SessionErrorValue::Utf8Error(error),
71         }
72     }
73 }
74 
75 impl From<PackerError> for SessionError {
from(error: PackerError) -> Self76     fn from(error: PackerError) -> Self {
77         SessionError {
78             value: SessionErrorValue::PackerError(error),
79         }
80     }
81 }
82 
83 impl From<UnPackerError> for SessionError {
from(error: UnPackerError) -> Self84     fn from(error: UnPackerError) -> Self {
85         SessionError {
86             value: SessionErrorValue::UnPackerError(error),
87         }
88     }
89 }
90 
91 impl From<ChannelError> for SessionError {
from(error: ChannelError) -> Self92     fn from(error: ChannelError) -> Self {
93         SessionError {
94             value: SessionErrorValue::ChannelError(error),
95         }
96     }
97 }
98 
99 impl From<RecvError> for SessionError {
from(error: RecvError) -> Self100     fn from(error: RecvError) -> Self {
101         SessionError {
102             value: SessionErrorValue::RecvError(error),
103         }
104     }
105 }
106 
107 impl fmt::Display for SessionError {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result108     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
109         fmt::Display::fmt(&self.value, f)
110     }
111 }
112 
113 impl Fail for SessionError {
cause(&self) -> Option<&dyn Fail>114     fn cause(&self) -> Option<&dyn Fail> {
115         self.value.cause()
116     }
117 
backtrace(&self) -> Option<&Backtrace>118     fn backtrace(&self) -> Option<&Backtrace> {
119         self.value.backtrace()
120     }
121 }
122