1use std::error::Error;
4use std::fmt;
5
6pub use crate::crypto::DtlsError;
8pub use crate::io::NetError;
9pub use crate::packet::{PacketError, Vp8DescriptorError, Vp8PatchError};
10pub use crate::rtp_::RtpError;
11pub use crate::sctp::ProtoError;
12pub use crate::sctp::SctpError;
13pub use crate::sdp::SdpError;
14pub use is::IceError;
15
16use crate::{Direction, KeyframeRequestKind, Mid, Pt, Rid};
17
18#[derive(Debug)]
20#[non_exhaustive]
21pub enum RtcError {
22 RemoteSdp(String),
24
25 Sdp(SdpError),
27
28 Rtp(RtpError),
30
31 Io(std::io::Error),
33
34 Dtls(DtlsError),
36
37 Packet(Mid, Pt, PacketError),
39
40 UnknownPt(Pt),
42
43 UnknownRid(Rid),
45
46 NoSenderSource,
48
49 ResendRequiresRtxPt,
51
52 NotSendingDirection(Direction),
54
55 NotReceivingDirection,
57
58 NoReceiverSource(Option<Rid>),
60
61 FeedbackNotEnabled(KeyframeRequestKind),
64
65 Net(NetError),
67
68 Ice(IceError),
70
71 Sctp(SctpError),
73
74 ChangesOutOfOrder,
83
84 WriteWithoutPoll,
87}
88
89impl fmt::Display for RtcError {
90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91 match self {
92 RtcError::RemoteSdp(msg) => write!(f, "remote sdp: {}", msg),
93 RtcError::Sdp(err) => write!(f, "{}", err),
94 RtcError::Rtp(err) => write!(f, "{}", err),
95 RtcError::Io(err) => write!(f, "{}", err),
96 RtcError::Dtls(err) => write!(f, "{}", err),
97 RtcError::Packet(mid, pt, err) => write!(f, "{} {} {}", mid, pt, err),
98 RtcError::UnknownPt(pt) => write!(f, "PT is unknown {}", pt),
99 RtcError::UnknownRid(rid) => write!(f, "RID is unknown {}", rid),
100 RtcError::NoSenderSource => write!(f, "No sender source"),
101 RtcError::ResendRequiresRtxPt => write!(
102 f,
103 "When outgoing stream has RTX, write_rtp must be called with rtp_pt set"
104 ),
105 RtcError::NotSendingDirection(dir) => {
106 write!(f, "Direction does not allow sending: {}", dir)
107 }
108 RtcError::NotReceivingDirection => write!(f, "Direction does not allow receiving"),
109 RtcError::NoReceiverSource(rid) => write!(f, "No receiver source (rid: {:?})", rid),
110 RtcError::FeedbackNotEnabled(kind) => {
111 write!(f, "Requested feedback is not enabled: {:?}", kind)
112 }
113 RtcError::Net(err) => write!(f, "{}", err),
114 RtcError::Ice(err) => write!(f, "{}", err),
115 RtcError::Sctp(err) => write!(f, "{}", err),
116 RtcError::ChangesOutOfOrder => write!(f, "Changes made out of order"),
117 RtcError::WriteWithoutPoll => write!(
118 f,
119 "Consecutive calls to write() without poll_output() in between"
120 ),
121 }
122 }
123}
124
125impl Error for RtcError {
126 fn source(&self) -> Option<&(dyn Error + 'static)> {
127 match self {
128 RtcError::Sdp(err) => Some(err),
129 RtcError::Rtp(err) => Some(err),
130 RtcError::Io(err) => Some(err),
131 RtcError::Dtls(err) => Some(err),
132 RtcError::Packet(_, _, err) => Some(err),
133 RtcError::Net(err) => Some(err),
134 RtcError::Ice(err) => Some(err),
135 RtcError::Sctp(err) => Some(err),
136 _ => None,
137 }
138 }
139}
140
141impl From<SdpError> for RtcError {
143 fn from(err: SdpError) -> Self {
144 RtcError::Sdp(err)
145 }
146}
147
148impl From<RtpError> for RtcError {
149 fn from(err: RtpError) -> Self {
150 RtcError::Rtp(err)
151 }
152}
153
154impl From<std::io::Error> for RtcError {
155 fn from(err: std::io::Error) -> Self {
156 RtcError::Io(err)
157 }
158}
159
160impl From<DtlsError> for RtcError {
161 fn from(err: DtlsError) -> Self {
162 RtcError::Dtls(err)
163 }
164}
165
166impl From<NetError> for RtcError {
167 fn from(err: NetError) -> Self {
168 RtcError::Net(err)
169 }
170}
171
172impl From<IceError> for RtcError {
173 fn from(err: IceError) -> Self {
174 RtcError::Ice(err)
175 }
176}
177
178impl From<SctpError> for RtcError {
179 fn from(err: SctpError) -> Self {
180 RtcError::Sctp(err)
181 }
182}