xref: /xiu/protocol/rtmp/src/session/errors.rs (revision 06c50324)
1 use {
2     crate::{
3         amf0::errors::Amf0WriteError,
4         cache::errors::CacheError,
5         chunk::errors::{PackError, UnpackError},
6         handshake::errors::HandshakeError,
7         messages::errors::MessageError,
8         netconnection::errors::NetConnectionError,
9         netstream::errors::NetStreamError,
10         protocol_control_messages::errors::ControlMessagesError,
11         user_control_messages::errors::EventMessagesError,
12     },
13     bytesio::{bytes_errors::BytesWriteError, bytesio_errors::BytesIOError},
14     failure::{Backtrace, Fail},
15     std::fmt,
16 };
17 
18 #[derive(Debug)]
19 pub struct SessionError {
20     pub value: SessionErrorValue,
21 }
22 
23 #[derive(Debug, Fail)]
24 pub enum SessionErrorValue {
25     #[fail(display = "amf0 write error: {}\n", _0)]
26     Amf0WriteError(#[cause] Amf0WriteError),
27     #[fail(display = "bytes write error: {}\n", _0)]
28     BytesWriteError(#[cause] BytesWriteError),
29     // #[fail(display = "timeout error: {}\n", _0)]
30     // TimeoutError(#[cause] Elapsed),
31     #[fail(display = "unpack error: {}\n", _0)]
32     UnPackError(#[cause] UnpackError),
33 
34     #[fail(display = "message error: {}\n", _0)]
35     MessageError(#[cause] MessageError),
36     #[fail(display = "control message error: {}\n", _0)]
37     ControlMessagesError(#[cause] ControlMessagesError),
38     #[fail(display = "net connection error: {}\n", _0)]
39     NetConnectionError(#[cause] NetConnectionError),
40     #[fail(display = "net stream error: {}\n", _0)]
41     NetStreamError(#[cause] NetStreamError),
42 
43     #[fail(display = "event messages error: {}\n", _0)]
44     EventMessagesError(#[cause] EventMessagesError),
45     #[fail(display = "net io error: {}\n", _0)]
46     BytesIOError(#[cause] BytesIOError),
47     #[fail(display = "pack error: {}\n", _0)]
48     PackError(#[cause] PackError),
49     #[fail(display = "handshake error: {}\n", _0)]
50     HandshakeError(#[cause] HandshakeError),
51     #[fail(display = "cache error name: {}\n", _0)]
52     CacheError(#[cause] CacheError),
53 
54     #[fail(display = "amf0 count not correct error\n")]
55     Amf0ValueCountNotCorrect,
56     #[fail(display = "amf0 value type not correct error\n")]
57     Amf0ValueTypeNotCorrect,
58     #[fail(display = "stream hub event send error\n")]
59     StreamHubEventSendErr,
60     #[fail(display = "none frame data sender error\n")]
61     NoneFrameDataSender,
62     #[fail(display = "none frame data receiver error\n")]
63     NoneFrameDataReceiver,
64     #[fail(display = "send frame data error\n")]
65     SendFrameDataErr,
66     #[fail(display = "subscribe count limit is reached.\n")]
67     SubscribeCountLimitReach,
68 
69     #[fail(display = "no app name error\n")]
70     NoAppName,
71     #[fail(display = "no media data can be received now.\n")]
72     NoMediaDataReceived,
73 
74     #[fail(display = "session is finished.")]
75     Finish,
76 }
77 
78 impl From<Amf0WriteError> for SessionError {
79     fn from(error: Amf0WriteError) -> Self {
80         SessionError {
81             value: SessionErrorValue::Amf0WriteError(error),
82         }
83     }
84 }
85 
86 impl From<BytesWriteError> for SessionError {
87     fn from(error: BytesWriteError) -> Self {
88         SessionError {
89             value: SessionErrorValue::BytesWriteError(error),
90         }
91     }
92 }
93 
94 // impl From<Elapsed> for SessionError {
95 //     fn from(error: Elapsed) -> Self {
96 //         SessionError {
97 //             value: SessionErrorValue::TimeoutError(error),
98 //         }
99 //     }
100 // }
101 
102 impl From<UnpackError> for SessionError {
103     fn from(error: UnpackError) -> Self {
104         SessionError {
105             value: SessionErrorValue::UnPackError(error),
106         }
107     }
108 }
109 
110 impl From<MessageError> for SessionError {
111     fn from(error: MessageError) -> Self {
112         SessionError {
113             value: SessionErrorValue::MessageError(error),
114         }
115     }
116 }
117 
118 impl From<ControlMessagesError> for SessionError {
119     fn from(error: ControlMessagesError) -> Self {
120         SessionError {
121             value: SessionErrorValue::ControlMessagesError(error),
122         }
123     }
124 }
125 
126 impl From<NetConnectionError> for SessionError {
127     fn from(error: NetConnectionError) -> Self {
128         SessionError {
129             value: SessionErrorValue::NetConnectionError(error),
130         }
131     }
132 }
133 
134 impl From<NetStreamError> for SessionError {
135     fn from(error: NetStreamError) -> Self {
136         SessionError {
137             value: SessionErrorValue::NetStreamError(error),
138         }
139     }
140 }
141 
142 impl From<EventMessagesError> for SessionError {
143     fn from(error: EventMessagesError) -> Self {
144         SessionError {
145             value: SessionErrorValue::EventMessagesError(error),
146         }
147     }
148 }
149 
150 impl From<BytesIOError> for SessionError {
151     fn from(error: BytesIOError) -> Self {
152         SessionError {
153             value: SessionErrorValue::BytesIOError(error),
154         }
155     }
156 }
157 
158 impl From<PackError> for SessionError {
159     fn from(error: PackError) -> Self {
160         SessionError {
161             value: SessionErrorValue::PackError(error),
162         }
163     }
164 }
165 
166 impl From<HandshakeError> for SessionError {
167     fn from(error: HandshakeError) -> Self {
168         SessionError {
169             value: SessionErrorValue::HandshakeError(error),
170         }
171     }
172 }
173 
174 impl From<CacheError> for SessionError {
175     fn from(error: CacheError) -> Self {
176         SessionError {
177             value: SessionErrorValue::CacheError(error),
178         }
179     }
180 }
181 
182 impl fmt::Display for SessionError {
183     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
184         fmt::Display::fmt(&self.value, f)
185     }
186 }
187 
188 impl Fail for SessionError {
189     fn cause(&self) -> Option<&dyn Fail> {
190         self.value.cause()
191     }
192 
193     fn backtrace(&self) -> Option<&Backtrace> {
194         self.value.backtrace()
195     }
196 }
197