135844cc6SHarlanC use crate::amf0::errors::Amf0WriteError; 235844cc6SHarlanC use crate::chunk::errors::PackError; 30bce4e4cSHarlanC use crate::chunk::errors::UnpackError; 435844cc6SHarlanC use crate::handshake::errors::HandshakeError; 50bce4e4cSHarlanC use crate::messages::errors::MessageError; 60bce4e4cSHarlanC use crate::netconnection::errors::NetConnectionError; 70bce4e4cSHarlanC use crate::netstream::errors::NetStreamError; 80bce4e4cSHarlanC use crate::protocol_control_messages::errors::ControlMessagesError; 90bce4e4cSHarlanC use crate::user_control_messages::errors::EventMessagesError; 100bce4e4cSHarlanC 119a3b6c39SHarlanC use netio::bytes_errors::BytesWriteError; 129a3b6c39SHarlanC use netio::netio_errors::NetIOError; 139a3b6c39SHarlanC 140bce4e4cSHarlanC use tokio::time::Elapsed; 150bce4e4cSHarlanC 16*c2f3fbfaSHarlanC use failure::{Backtrace, Fail}; 17*c2f3fbfaSHarlanC use std::fmt; 18*c2f3fbfaSHarlanC 19*c2f3fbfaSHarlanC #[derive(Debug)] 200bce4e4cSHarlanC pub struct SessionError { 210bce4e4cSHarlanC pub value: SessionErrorValue, 220bce4e4cSHarlanC } 230bce4e4cSHarlanC 24*c2f3fbfaSHarlanC #[derive(Debug, Fail)] 250bce4e4cSHarlanC pub enum SessionErrorValue { 26*c2f3fbfaSHarlanC #[fail(display = "amf0 write error: {}", _0)] 27*c2f3fbfaSHarlanC Amf0WriteError(#[cause] Amf0WriteError), 28*c2f3fbfaSHarlanC #[fail(display = "bytes write error: {}", _0)] 29*c2f3fbfaSHarlanC BytesWriteError(#[cause] BytesWriteError), 30*c2f3fbfaSHarlanC #[fail(display = "timeout error: {}", _0)] 31*c2f3fbfaSHarlanC TimeoutError(#[cause] Elapsed), 32*c2f3fbfaSHarlanC #[fail(display = "unpack error: {}", _0)] 33*c2f3fbfaSHarlanC UnPackError(#[cause] UnpackError), 340bce4e4cSHarlanC 35*c2f3fbfaSHarlanC 36*c2f3fbfaSHarlanC #[fail(display = "message error: {}", _0)] 37*c2f3fbfaSHarlanC MessageError(#[cause] MessageError), 38*c2f3fbfaSHarlanC #[fail(display = "control message error: {}", _0)] 39*c2f3fbfaSHarlanC ControlMessagesError(#[cause] ControlMessagesError), 40*c2f3fbfaSHarlanC #[fail(display = "net connection error: {}", _0)] 41*c2f3fbfaSHarlanC NetConnectionError(#[cause] NetConnectionError), 42*c2f3fbfaSHarlanC #[fail(display = "net stream error: {}", _0)] 43*c2f3fbfaSHarlanC NetStreamError(#[cause] NetStreamError), 44*c2f3fbfaSHarlanC 45*c2f3fbfaSHarlanC #[fail(display = "event messages error: {}", _0)] 46*c2f3fbfaSHarlanC EventMessagesError(#[cause] EventMessagesError), 47*c2f3fbfaSHarlanC #[fail(display = "net io error: {}", _0)] 48*c2f3fbfaSHarlanC NetIOError(#[cause] NetIOError), 49*c2f3fbfaSHarlanC #[fail(display = "pack error: {}", _0)] 50*c2f3fbfaSHarlanC PackError(#[cause] PackError), 51*c2f3fbfaSHarlanC #[fail(display = "handshake error: {}", _0)] 52*c2f3fbfaSHarlanC HandshakeError(#[cause] HandshakeError), 53*c2f3fbfaSHarlanC 54*c2f3fbfaSHarlanC #[fail(display = "amf0 count not correct error")] 550bce4e4cSHarlanC Amf0ValueCountNotCorrect, 56*c2f3fbfaSHarlanC #[fail(display = "amf0 value type not correct error")] 570bce4e4cSHarlanC Amf0ValueTypeNotCorrect, 58*c2f3fbfaSHarlanC #[fail(display = "channel event send error")] 591606f184SHarlanC ChannelEventSendErr, 60*c2f3fbfaSHarlanC #[fail(display = "none channel data sender error")] 611606f184SHarlanC NoneChannelDataSender, 62*c2f3fbfaSHarlanC #[fail(display = "none channel data receiver error")] 631606f184SHarlanC NoneChannelDataReceiver, 64*c2f3fbfaSHarlanC #[fail(display = "send channel data error")] 656fec14f0SHarlanC SendChannelDataErr, 666fec14f0SHarlanC 67*c2f3fbfaSHarlanC #[fail(display = "no app name error")] 686fec14f0SHarlanC NoAppName, 690bce4e4cSHarlanC } 700bce4e4cSHarlanC 710bce4e4cSHarlanC impl From<Amf0WriteError> for SessionError { 720bce4e4cSHarlanC fn from(error: Amf0WriteError) -> Self { 730bce4e4cSHarlanC SessionError { 740bce4e4cSHarlanC value: SessionErrorValue::Amf0WriteError(error), 750bce4e4cSHarlanC } 760bce4e4cSHarlanC } 770bce4e4cSHarlanC } 780bce4e4cSHarlanC 790bce4e4cSHarlanC impl From<BytesWriteError> for SessionError { 800bce4e4cSHarlanC fn from(error: BytesWriteError) -> Self { 810bce4e4cSHarlanC SessionError { 820bce4e4cSHarlanC value: SessionErrorValue::BytesWriteError(error), 830bce4e4cSHarlanC } 840bce4e4cSHarlanC } 850bce4e4cSHarlanC } 860bce4e4cSHarlanC 870bce4e4cSHarlanC impl From<Elapsed> for SessionError { 880bce4e4cSHarlanC fn from(error: Elapsed) -> Self { 890bce4e4cSHarlanC SessionError { 900bce4e4cSHarlanC value: SessionErrorValue::TimeoutError(error), 910bce4e4cSHarlanC } 920bce4e4cSHarlanC } 930bce4e4cSHarlanC } 940bce4e4cSHarlanC 950bce4e4cSHarlanC impl From<UnpackError> for SessionError { 960bce4e4cSHarlanC fn from(error: UnpackError) -> Self { 970bce4e4cSHarlanC SessionError { 980bce4e4cSHarlanC value: SessionErrorValue::UnPackError(error), 990bce4e4cSHarlanC } 1000bce4e4cSHarlanC } 1010bce4e4cSHarlanC } 1020bce4e4cSHarlanC 1030bce4e4cSHarlanC impl From<MessageError> for SessionError { 1040bce4e4cSHarlanC fn from(error: MessageError) -> Self { 1050bce4e4cSHarlanC SessionError { 1060bce4e4cSHarlanC value: SessionErrorValue::MessageError(error), 1070bce4e4cSHarlanC } 1080bce4e4cSHarlanC } 1090bce4e4cSHarlanC } 1100bce4e4cSHarlanC 1110bce4e4cSHarlanC impl From<ControlMessagesError> for SessionError { 1120bce4e4cSHarlanC fn from(error: ControlMessagesError) -> Self { 1130bce4e4cSHarlanC SessionError { 1140bce4e4cSHarlanC value: SessionErrorValue::ControlMessagesError(error), 1150bce4e4cSHarlanC } 1160bce4e4cSHarlanC } 1170bce4e4cSHarlanC } 1180bce4e4cSHarlanC 1190bce4e4cSHarlanC impl From<NetConnectionError> for SessionError { 1200bce4e4cSHarlanC fn from(error: NetConnectionError) -> Self { 1210bce4e4cSHarlanC SessionError { 1220bce4e4cSHarlanC value: SessionErrorValue::NetConnectionError(error), 1230bce4e4cSHarlanC } 1240bce4e4cSHarlanC } 1250bce4e4cSHarlanC } 1260bce4e4cSHarlanC 1270bce4e4cSHarlanC impl From<NetStreamError> for SessionError { 1280bce4e4cSHarlanC fn from(error: NetStreamError) -> Self { 1290bce4e4cSHarlanC SessionError { 1300bce4e4cSHarlanC value: SessionErrorValue::NetStreamError(error), 1310bce4e4cSHarlanC } 1320bce4e4cSHarlanC } 1330bce4e4cSHarlanC } 1340bce4e4cSHarlanC 1350bce4e4cSHarlanC impl From<EventMessagesError> for SessionError { 1360bce4e4cSHarlanC fn from(error: EventMessagesError) -> Self { 1370bce4e4cSHarlanC SessionError { 1380bce4e4cSHarlanC value: SessionErrorValue::EventMessagesError(error), 1390bce4e4cSHarlanC } 1400bce4e4cSHarlanC } 1410bce4e4cSHarlanC } 1420bce4e4cSHarlanC 1430bce4e4cSHarlanC impl From<NetIOError> for SessionError { 1440bce4e4cSHarlanC fn from(error: NetIOError) -> Self { 1450bce4e4cSHarlanC SessionError { 1460bce4e4cSHarlanC value: SessionErrorValue::NetIOError(error), 1470bce4e4cSHarlanC } 1480bce4e4cSHarlanC } 1490bce4e4cSHarlanC } 1500bce4e4cSHarlanC 1510bce4e4cSHarlanC impl From<PackError> for SessionError { 1520bce4e4cSHarlanC fn from(error: PackError) -> Self { 1530bce4e4cSHarlanC SessionError { 1540bce4e4cSHarlanC value: SessionErrorValue::PackError(error), 1550bce4e4cSHarlanC } 1560bce4e4cSHarlanC } 1570bce4e4cSHarlanC } 1580bce4e4cSHarlanC 1590bce4e4cSHarlanC impl From<HandshakeError> for SessionError { 1600bce4e4cSHarlanC fn from(error: HandshakeError) -> Self { 1610bce4e4cSHarlanC SessionError { 1620bce4e4cSHarlanC value: SessionErrorValue::HandshakeError(error), 1630bce4e4cSHarlanC } 1640bce4e4cSHarlanC } 1650bce4e4cSHarlanC } 166*c2f3fbfaSHarlanC 167*c2f3fbfaSHarlanC impl fmt::Display for SessionError { 168*c2f3fbfaSHarlanC fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 169*c2f3fbfaSHarlanC fmt::Display::fmt(&self.value, f) 170*c2f3fbfaSHarlanC } 171*c2f3fbfaSHarlanC } 172*c2f3fbfaSHarlanC 173*c2f3fbfaSHarlanC impl Fail for SessionError { 174*c2f3fbfaSHarlanC fn cause(&self) -> Option<&dyn Fail> { 175*c2f3fbfaSHarlanC self.value.cause() 176*c2f3fbfaSHarlanC } 177*c2f3fbfaSHarlanC 178*c2f3fbfaSHarlanC fn backtrace(&self) -> Option<&Backtrace> { 179*c2f3fbfaSHarlanC self.value.backtrace() 180*c2f3fbfaSHarlanC } 181*c2f3fbfaSHarlanC } 182