xref: /xiu/protocol/rtsp/src/session/errors.rs (revision 8e71d710)
1 use {
2     crate::rtp::errors::PackerError,
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 };
9 
10 #[derive(Debug)]
11 pub struct SessionError {
12     pub value: SessionErrorValue,
13 }
14 
15 #[derive(Debug, Fail)]
16 pub enum SessionErrorValue {
17     #[fail(display = "net io error: {}\n", _0)]
18     BytesIOError(#[cause] BytesIOError),
19     #[fail(display = "bytes read error: {}\n", _0)]
20     BytesReadError(#[cause] BytesReadError),
21     #[fail(display = "bytes write error: {}\n", _0)]
22     BytesWriteError(#[cause] BytesWriteError),
23     #[fail(display = "Utf8Error: {}\n", _0)]
24     Utf8Error(#[cause] Utf8Error),
25     #[fail(display = "stream hub event send error\n")]
26     StreamHubEventSendErr,
27     #[fail(display = "cannot receive frame data from stream hub\n")]
28     CannotReceiveFrameData,
29     #[fail(display = "pack error: {}\n", _0)]
30     PackerError(#[cause] PackerError),
31 }
32 
33 impl From<BytesIOError> for SessionError {
34     fn from(error: BytesIOError) -> Self {
35         SessionError {
36             value: SessionErrorValue::BytesIOError(error),
37         }
38     }
39 }
40 
41 impl From<BytesReadError> for SessionError {
42     fn from(error: BytesReadError) -> Self {
43         SessionError {
44             value: SessionErrorValue::BytesReadError(error),
45         }
46     }
47 }
48 
49 impl From<BytesWriteError> for SessionError {
50     fn from(error: BytesWriteError) -> Self {
51         SessionError {
52             value: SessionErrorValue::BytesWriteError(error),
53         }
54     }
55 }
56 
57 impl From<Utf8Error> for SessionError {
58     fn from(error: Utf8Error) -> Self {
59         SessionError {
60             value: SessionErrorValue::Utf8Error(error),
61         }
62     }
63 }
64 
65 impl From<PackerError> for SessionError {
66     fn from(error: PackerError) -> Self {
67         SessionError {
68             value: SessionErrorValue::PackerError(error),
69         }
70     }
71 }
72 
73 impl fmt::Display for SessionError {
74     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
75         fmt::Display::fmt(&self.value, f)
76     }
77 }
78 
79 impl Fail for SessionError {
80     fn cause(&self) -> Option<&dyn Fail> {
81         self.value.cause()
82     }
83 
84     fn backtrace(&self) -> Option<&Backtrace> {
85         self.value.backtrace()
86     }
87 }
88