14435d79dSHarlanC use { 24435d79dSHarlanC crate::{ 34435d79dSHarlanC amf0::errors::Amf0WriteError, 48e71d710SHarlan cache::errors::CacheError, 54435d79dSHarlanC chunk::errors::{PackError, UnpackError}, 64435d79dSHarlanC handshake::errors::HandshakeError, 74435d79dSHarlanC messages::errors::MessageError, 84435d79dSHarlanC netconnection::errors::NetConnectionError, 94435d79dSHarlanC netstream::errors::NetStreamError, 104435d79dSHarlanC protocol_control_messages::errors::ControlMessagesError, 114435d79dSHarlanC user_control_messages::errors::EventMessagesError, 124435d79dSHarlanC }, 1388325f54SHarlanC bytesio::{bytes_errors::BytesWriteError, bytesio_errors::BytesIOError}, 145359bb99Swawacry failure::{Backtrace, Fail}, 154435d79dSHarlanC std::fmt, 16*a4ef5d6cSHarlanC streamhub::errors::ChannelError, 17*a4ef5d6cSHarlanC tokio::sync::oneshot::error::RecvError, 184435d79dSHarlanC }; 19c2f3fbfaSHarlanC 20c2f3fbfaSHarlanC #[derive(Debug)] 210bce4e4cSHarlanC pub struct SessionError { 220bce4e4cSHarlanC pub value: SessionErrorValue, 230bce4e4cSHarlanC } 240bce4e4cSHarlanC 25c2f3fbfaSHarlanC #[derive(Debug, Fail)] 260bce4e4cSHarlanC pub enum SessionErrorValue { 2769de9bbdSHarlanC #[fail(display = "amf0 write error: {}", _0)] 28c2f3fbfaSHarlanC Amf0WriteError(#[cause] Amf0WriteError), 2969de9bbdSHarlanC #[fail(display = "bytes write error: {}", _0)] 30c2f3fbfaSHarlanC BytesWriteError(#[cause] BytesWriteError), 3169de9bbdSHarlanC // #[fail(display = "timeout error: {}", _0)] 32fe91dfa7SHarlanC // TimeoutError(#[cause] Elapsed), 3369de9bbdSHarlanC #[fail(display = "unpack error: {}", _0)] 34c2f3fbfaSHarlanC UnPackError(#[cause] UnpackError), 350bce4e4cSHarlanC 3669de9bbdSHarlanC #[fail(display = "message error: {}", _0)] 37c2f3fbfaSHarlanC MessageError(#[cause] MessageError), 3869de9bbdSHarlanC #[fail(display = "control message error: {}", _0)] 39c2f3fbfaSHarlanC ControlMessagesError(#[cause] ControlMessagesError), 4069de9bbdSHarlanC #[fail(display = "net connection error: {}", _0)] 41c2f3fbfaSHarlanC NetConnectionError(#[cause] NetConnectionError), 4269de9bbdSHarlanC #[fail(display = "net stream error: {}", _0)] 43c2f3fbfaSHarlanC NetStreamError(#[cause] NetStreamError), 44c2f3fbfaSHarlanC 4569de9bbdSHarlanC #[fail(display = "event messages error: {}", _0)] 46c2f3fbfaSHarlanC EventMessagesError(#[cause] EventMessagesError), 4769de9bbdSHarlanC #[fail(display = "net io error: {}", _0)] 4888325f54SHarlanC BytesIOError(#[cause] BytesIOError), 4969de9bbdSHarlanC #[fail(display = "pack error: {}", _0)] 50c2f3fbfaSHarlanC PackError(#[cause] PackError), 5169de9bbdSHarlanC #[fail(display = "handshake error: {}", _0)] 52c2f3fbfaSHarlanC HandshakeError(#[cause] HandshakeError), 5369de9bbdSHarlanC #[fail(display = "cache error name: {}", _0)] 548e71d710SHarlan CacheError(#[cause] CacheError), 55*a4ef5d6cSHarlanC #[fail(display = "tokio: oneshot receiver err: {}", _0)] 56*a4ef5d6cSHarlanC RecvError(#[cause] RecvError), 57*a4ef5d6cSHarlanC #[fail(display = "streamhub channel err: {}", _0)] 58*a4ef5d6cSHarlanC ChannelError(#[cause] ChannelError), 59c2f3fbfaSHarlanC 6069de9bbdSHarlanC #[fail(display = "amf0 count not correct error")] 610bce4e4cSHarlanC Amf0ValueCountNotCorrect, 6269de9bbdSHarlanC #[fail(display = "amf0 value type not correct error")] 630bce4e4cSHarlanC Amf0ValueTypeNotCorrect, 6469de9bbdSHarlanC #[fail(display = "stream hub event send error")] 658e71d710SHarlan StreamHubEventSendErr, 6669de9bbdSHarlanC #[fail(display = "none frame data sender error")] 678e71d710SHarlan NoneFrameDataSender, 6869de9bbdSHarlanC #[fail(display = "none frame data receiver error")] 698e71d710SHarlan NoneFrameDataReceiver, 7069de9bbdSHarlanC #[fail(display = "send frame data error")] 718e71d710SHarlan SendFrameDataErr, 7269de9bbdSHarlanC #[fail(display = "subscribe count limit is reached.")] 73b1840569SHarlanC SubscribeCountLimitReach, 746fec14f0SHarlanC 7569de9bbdSHarlanC #[fail(display = "no app name error")] 766fec14f0SHarlanC NoAppName, 7769de9bbdSHarlanC #[fail(display = "no media data can be received now.")] 785359bb99Swawacry NoMediaDataReceived, 79f8169385SHarlanC 80f8169385SHarlanC #[fail(display = "session is finished.")] 81f8169385SHarlanC Finish, 820bce4e4cSHarlanC } 830bce4e4cSHarlanC 840bce4e4cSHarlanC impl From<Amf0WriteError> for SessionError { from(error: Amf0WriteError) -> Self850bce4e4cSHarlanC fn from(error: Amf0WriteError) -> Self { 860bce4e4cSHarlanC SessionError { 870bce4e4cSHarlanC value: SessionErrorValue::Amf0WriteError(error), 880bce4e4cSHarlanC } 890bce4e4cSHarlanC } 900bce4e4cSHarlanC } 910bce4e4cSHarlanC 920bce4e4cSHarlanC impl From<BytesWriteError> for SessionError { from(error: BytesWriteError) -> Self930bce4e4cSHarlanC fn from(error: BytesWriteError) -> Self { 940bce4e4cSHarlanC SessionError { 950bce4e4cSHarlanC value: SessionErrorValue::BytesWriteError(error), 960bce4e4cSHarlanC } 970bce4e4cSHarlanC } 980bce4e4cSHarlanC } 990bce4e4cSHarlanC 100fe91dfa7SHarlanC // impl From<Elapsed> for SessionError { 101fe91dfa7SHarlanC // fn from(error: Elapsed) -> Self { 102fe91dfa7SHarlanC // SessionError { 103fe91dfa7SHarlanC // value: SessionErrorValue::TimeoutError(error), 104fe91dfa7SHarlanC // } 105fe91dfa7SHarlanC // } 106fe91dfa7SHarlanC // } 1070bce4e4cSHarlanC 1080bce4e4cSHarlanC impl From<UnpackError> for SessionError { from(error: UnpackError) -> Self1090bce4e4cSHarlanC fn from(error: UnpackError) -> Self { 1100bce4e4cSHarlanC SessionError { 1110bce4e4cSHarlanC value: SessionErrorValue::UnPackError(error), 1120bce4e4cSHarlanC } 1130bce4e4cSHarlanC } 1140bce4e4cSHarlanC } 1150bce4e4cSHarlanC 1160bce4e4cSHarlanC impl From<MessageError> for SessionError { from(error: MessageError) -> Self1170bce4e4cSHarlanC fn from(error: MessageError) -> Self { 1180bce4e4cSHarlanC SessionError { 1190bce4e4cSHarlanC value: SessionErrorValue::MessageError(error), 1200bce4e4cSHarlanC } 1210bce4e4cSHarlanC } 1220bce4e4cSHarlanC } 1230bce4e4cSHarlanC 1240bce4e4cSHarlanC impl From<ControlMessagesError> for SessionError { from(error: ControlMessagesError) -> Self1250bce4e4cSHarlanC fn from(error: ControlMessagesError) -> Self { 1260bce4e4cSHarlanC SessionError { 1270bce4e4cSHarlanC value: SessionErrorValue::ControlMessagesError(error), 1280bce4e4cSHarlanC } 1290bce4e4cSHarlanC } 1300bce4e4cSHarlanC } 1310bce4e4cSHarlanC 1320bce4e4cSHarlanC impl From<NetConnectionError> for SessionError { from(error: NetConnectionError) -> Self1330bce4e4cSHarlanC fn from(error: NetConnectionError) -> Self { 1340bce4e4cSHarlanC SessionError { 1350bce4e4cSHarlanC value: SessionErrorValue::NetConnectionError(error), 1360bce4e4cSHarlanC } 1370bce4e4cSHarlanC } 1380bce4e4cSHarlanC } 1390bce4e4cSHarlanC 1400bce4e4cSHarlanC impl From<NetStreamError> for SessionError { from(error: NetStreamError) -> Self1410bce4e4cSHarlanC fn from(error: NetStreamError) -> Self { 1420bce4e4cSHarlanC SessionError { 1430bce4e4cSHarlanC value: SessionErrorValue::NetStreamError(error), 1440bce4e4cSHarlanC } 1450bce4e4cSHarlanC } 1460bce4e4cSHarlanC } 1470bce4e4cSHarlanC 1480bce4e4cSHarlanC impl From<EventMessagesError> for SessionError { from(error: EventMessagesError) -> Self1490bce4e4cSHarlanC fn from(error: EventMessagesError) -> Self { 1500bce4e4cSHarlanC SessionError { 1510bce4e4cSHarlanC value: SessionErrorValue::EventMessagesError(error), 1520bce4e4cSHarlanC } 1530bce4e4cSHarlanC } 1540bce4e4cSHarlanC } 1550bce4e4cSHarlanC 15688325f54SHarlanC impl From<BytesIOError> for SessionError { from(error: BytesIOError) -> Self15788325f54SHarlanC fn from(error: BytesIOError) -> Self { 1580bce4e4cSHarlanC SessionError { 15988325f54SHarlanC value: SessionErrorValue::BytesIOError(error), 1600bce4e4cSHarlanC } 1610bce4e4cSHarlanC } 1620bce4e4cSHarlanC } 1630bce4e4cSHarlanC 1640bce4e4cSHarlanC impl From<PackError> for SessionError { from(error: PackError) -> Self1650bce4e4cSHarlanC fn from(error: PackError) -> Self { 1660bce4e4cSHarlanC SessionError { 1670bce4e4cSHarlanC value: SessionErrorValue::PackError(error), 1680bce4e4cSHarlanC } 1690bce4e4cSHarlanC } 1700bce4e4cSHarlanC } 1710bce4e4cSHarlanC 1720bce4e4cSHarlanC impl From<HandshakeError> for SessionError { from(error: HandshakeError) -> Self1730bce4e4cSHarlanC fn from(error: HandshakeError) -> Self { 1740bce4e4cSHarlanC SessionError { 1750bce4e4cSHarlanC value: SessionErrorValue::HandshakeError(error), 1760bce4e4cSHarlanC } 1770bce4e4cSHarlanC } 1780bce4e4cSHarlanC } 179c2f3fbfaSHarlanC 1808e71d710SHarlan impl From<CacheError> for SessionError { from(error: CacheError) -> Self1818e71d710SHarlan fn from(error: CacheError) -> Self { 1828e71d710SHarlan SessionError { 1838e71d710SHarlan value: SessionErrorValue::CacheError(error), 1848e71d710SHarlan } 1858e71d710SHarlan } 1868e71d710SHarlan } 1878e71d710SHarlan 188*a4ef5d6cSHarlanC impl From<RecvError> for SessionError { from(error: RecvError) -> Self189*a4ef5d6cSHarlanC fn from(error: RecvError) -> Self { 190*a4ef5d6cSHarlanC SessionError { 191*a4ef5d6cSHarlanC value: SessionErrorValue::RecvError(error), 192*a4ef5d6cSHarlanC } 193*a4ef5d6cSHarlanC } 194*a4ef5d6cSHarlanC } 195*a4ef5d6cSHarlanC 196*a4ef5d6cSHarlanC impl From<ChannelError> for SessionError { from(error: ChannelError) -> Self197*a4ef5d6cSHarlanC fn from(error: ChannelError) -> Self { 198*a4ef5d6cSHarlanC SessionError { 199*a4ef5d6cSHarlanC value: SessionErrorValue::ChannelError(error), 200*a4ef5d6cSHarlanC } 201*a4ef5d6cSHarlanC } 202*a4ef5d6cSHarlanC } 203*a4ef5d6cSHarlanC 204c2f3fbfaSHarlanC impl fmt::Display for SessionError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result205c2f3fbfaSHarlanC fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 206c2f3fbfaSHarlanC fmt::Display::fmt(&self.value, f) 207c2f3fbfaSHarlanC } 208c2f3fbfaSHarlanC } 209c2f3fbfaSHarlanC 210c2f3fbfaSHarlanC impl Fail for SessionError { cause(&self) -> Option<&dyn Fail>211c2f3fbfaSHarlanC fn cause(&self) -> Option<&dyn Fail> { 212c2f3fbfaSHarlanC self.value.cause() 213c2f3fbfaSHarlanC } 214c2f3fbfaSHarlanC backtrace(&self) -> Option<&Backtrace>215c2f3fbfaSHarlanC fn backtrace(&self) -> Option<&Backtrace> { 216c2f3fbfaSHarlanC self.value.backtrace() 217c2f3fbfaSHarlanC } 218c2f3fbfaSHarlanC } 219