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 streamhub::errors::ChannelError, 17 tokio::sync::oneshot::error::RecvError, 18 }; 19 20 #[derive(Debug)] 21 pub struct SessionError { 22 pub value: SessionErrorValue, 23 } 24 25 #[derive(Debug, Fail)] 26 pub enum SessionErrorValue { 27 #[fail(display = "amf0 write error: {}", _0)] 28 Amf0WriteError(#[cause] Amf0WriteError), 29 #[fail(display = "bytes write error: {}", _0)] 30 BytesWriteError(#[cause] BytesWriteError), 31 // #[fail(display = "timeout error: {}", _0)] 32 // TimeoutError(#[cause] Elapsed), 33 #[fail(display = "unpack error: {}", _0)] 34 UnPackError(#[cause] UnpackError), 35 36 #[fail(display = "message error: {}", _0)] 37 MessageError(#[cause] MessageError), 38 #[fail(display = "control message error: {}", _0)] 39 ControlMessagesError(#[cause] ControlMessagesError), 40 #[fail(display = "net connection error: {}", _0)] 41 NetConnectionError(#[cause] NetConnectionError), 42 #[fail(display = "net stream error: {}", _0)] 43 NetStreamError(#[cause] NetStreamError), 44 45 #[fail(display = "event messages error: {}", _0)] 46 EventMessagesError(#[cause] EventMessagesError), 47 #[fail(display = "net io error: {}", _0)] 48 BytesIOError(#[cause] BytesIOError), 49 #[fail(display = "pack error: {}", _0)] 50 PackError(#[cause] PackError), 51 #[fail(display = "handshake error: {}", _0)] 52 HandshakeError(#[cause] HandshakeError), 53 #[fail(display = "cache error name: {}", _0)] 54 CacheError(#[cause] CacheError), 55 #[fail(display = "tokio: oneshot receiver err: {}", _0)] 56 RecvError(#[cause] RecvError), 57 #[fail(display = "streamhub channel err: {}", _0)] 58 ChannelError(#[cause] ChannelError), 59 60 #[fail(display = "amf0 count not correct error")] 61 Amf0ValueCountNotCorrect, 62 #[fail(display = "amf0 value type not correct error")] 63 Amf0ValueTypeNotCorrect, 64 #[fail(display = "stream hub event send error")] 65 StreamHubEventSendErr, 66 #[fail(display = "none frame data sender error")] 67 NoneFrameDataSender, 68 #[fail(display = "none frame data receiver error")] 69 NoneFrameDataReceiver, 70 #[fail(display = "send frame data error")] 71 SendFrameDataErr, 72 #[fail(display = "subscribe count limit is reached.")] 73 SubscribeCountLimitReach, 74 75 #[fail(display = "no app name error")] 76 NoAppName, 77 #[fail(display = "no media data can be received now.")] 78 NoMediaDataReceived, 79 80 #[fail(display = "session is finished.")] 81 Finish, 82 } 83 84 impl From<Amf0WriteError> for SessionError { from(error: Amf0WriteError) -> Self85 fn from(error: Amf0WriteError) -> Self { 86 SessionError { 87 value: SessionErrorValue::Amf0WriteError(error), 88 } 89 } 90 } 91 92 impl From<BytesWriteError> for SessionError { from(error: BytesWriteError) -> Self93 fn from(error: BytesWriteError) -> Self { 94 SessionError { 95 value: SessionErrorValue::BytesWriteError(error), 96 } 97 } 98 } 99 100 // impl From<Elapsed> for SessionError { 101 // fn from(error: Elapsed) -> Self { 102 // SessionError { 103 // value: SessionErrorValue::TimeoutError(error), 104 // } 105 // } 106 // } 107 108 impl From<UnpackError> for SessionError { from(error: UnpackError) -> Self109 fn from(error: UnpackError) -> Self { 110 SessionError { 111 value: SessionErrorValue::UnPackError(error), 112 } 113 } 114 } 115 116 impl From<MessageError> for SessionError { from(error: MessageError) -> Self117 fn from(error: MessageError) -> Self { 118 SessionError { 119 value: SessionErrorValue::MessageError(error), 120 } 121 } 122 } 123 124 impl From<ControlMessagesError> for SessionError { from(error: ControlMessagesError) -> Self125 fn from(error: ControlMessagesError) -> Self { 126 SessionError { 127 value: SessionErrorValue::ControlMessagesError(error), 128 } 129 } 130 } 131 132 impl From<NetConnectionError> for SessionError { from(error: NetConnectionError) -> Self133 fn from(error: NetConnectionError) -> Self { 134 SessionError { 135 value: SessionErrorValue::NetConnectionError(error), 136 } 137 } 138 } 139 140 impl From<NetStreamError> for SessionError { from(error: NetStreamError) -> Self141 fn from(error: NetStreamError) -> Self { 142 SessionError { 143 value: SessionErrorValue::NetStreamError(error), 144 } 145 } 146 } 147 148 impl From<EventMessagesError> for SessionError { from(error: EventMessagesError) -> Self149 fn from(error: EventMessagesError) -> Self { 150 SessionError { 151 value: SessionErrorValue::EventMessagesError(error), 152 } 153 } 154 } 155 156 impl From<BytesIOError> for SessionError { from(error: BytesIOError) -> Self157 fn from(error: BytesIOError) -> Self { 158 SessionError { 159 value: SessionErrorValue::BytesIOError(error), 160 } 161 } 162 } 163 164 impl From<PackError> for SessionError { from(error: PackError) -> Self165 fn from(error: PackError) -> Self { 166 SessionError { 167 value: SessionErrorValue::PackError(error), 168 } 169 } 170 } 171 172 impl From<HandshakeError> for SessionError { from(error: HandshakeError) -> Self173 fn from(error: HandshakeError) -> Self { 174 SessionError { 175 value: SessionErrorValue::HandshakeError(error), 176 } 177 } 178 } 179 180 impl From<CacheError> for SessionError { from(error: CacheError) -> Self181 fn from(error: CacheError) -> Self { 182 SessionError { 183 value: SessionErrorValue::CacheError(error), 184 } 185 } 186 } 187 188 impl From<RecvError> for SessionError { from(error: RecvError) -> Self189 fn from(error: RecvError) -> Self { 190 SessionError { 191 value: SessionErrorValue::RecvError(error), 192 } 193 } 194 } 195 196 impl From<ChannelError> for SessionError { from(error: ChannelError) -> Self197 fn from(error: ChannelError) -> Self { 198 SessionError { 199 value: SessionErrorValue::ChannelError(error), 200 } 201 } 202 } 203 204 impl fmt::Display for SessionError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result205 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 206 fmt::Display::fmt(&self.value, f) 207 } 208 } 209 210 impl Fail for SessionError { cause(&self) -> Option<&dyn Fail>211 fn cause(&self) -> Option<&dyn Fail> { 212 self.value.cause() 213 } 214 backtrace(&self) -> Option<&Backtrace>215 fn backtrace(&self) -> Option<&Backtrace> { 216 self.value.backtrace() 217 } 218 } 219