1use thiserror::Error;
2use std::io;
3
4#[derive(Debug, Error, Clone)]
6pub enum Error {
7 #[error("Failed to encode RTP packet: {0}")]
9 EncodeError(String),
10
11 #[error("Failed to decode RTP packet: {0}")]
13 DecodeError(String),
14
15 #[error("Invalid RTP packet format: {0}")]
17 InvalidPacket(String),
18
19 #[error("Buffer too small for RTP packet: need {required} but have {available}")]
21 BufferTooSmall {
22 required: usize,
23 available: usize,
24 },
25
26 #[error("Invalid parameter: {0}")]
28 InvalidParameter(String),
29
30 #[error("IO error: {0}")]
32 IoError(String),
33
34 #[error("RTCP error: {0}")]
36 RtcpError(String),
37
38 #[error("RTP session error: {0}")]
40 SessionError(String),
41
42 #[error("Transport error: {0}")]
44 Transport(String),
45
46 #[error("Parse error: {0}")]
48 ParseError(String),
49
50 #[error("SRTP error: {0}")]
52 SrtpError(String),
53
54 #[error("Statistics error: {0}")]
56 StatsError(String),
57
58 #[error("Timing error: {0}")]
60 TimingError(String),
61
62 #[error("Invalid protocol version: {0}")]
64 InvalidProtocolVersion(String),
65
66 #[error("Unsupported feature: {0}")]
68 UnsupportedFeature(String),
69
70 #[error("Not implemented: {0}")]
72 NotImplemented(String),
73
74 #[error("Invalid state: {0}")]
76 InvalidState(String),
77
78 #[error("DTLS handshake error: {0}")]
80 DtlsHandshakeError(String),
81
82 #[error("DTLS alert received: {0}")]
84 DtlsAlertReceived(String),
85
86 #[error("Certificate validation error: {0}")]
88 CertificateValidationError(String),
89
90 #[error("Cryptographic error: {0}")]
92 CryptoError(String),
93
94 #[error("Invalid message: {0}")]
96 InvalidMessage(String),
97
98 #[error("Authentication failed: {0}")]
100 AuthenticationFailed(String),
101
102 #[error("Negotiation failed: {0}")]
104 NegotiationFailed(String),
105
106 #[error("Packet too short")]
108 PacketTooShort,
109
110 #[error("Operation timed out: {0}")]
112 Timeout(String),
113
114 #[error("Serialization error: {0}")]
116 SerializationError(String),
117}
118
119impl From<io::Error> for Error {
120 fn from(err: io::Error) -> Self {
121 Error::IoError(err.to_string())
122 }
123}
124
125#[cfg(test)]
126mod tests {
127 use super::*;
128
129 #[test]
130 fn test_error_display() {
131 let encode_err = Error::EncodeError("test error".to_string());
132 assert_eq!(encode_err.to_string(), "Failed to encode RTP packet: test error");
133
134 let buffer_err = Error::BufferTooSmall { required: 100, available: 50 };
135 assert_eq!(buffer_err.to_string(), "Buffer too small for RTP packet: need 100 but have 50");
136
137 let io_err = Error::from(io::Error::new(io::ErrorKind::NotFound, "file not found"));
138 assert!(io_err.to_string().contains("IO error"));
139 }
140}