1 use thiserror::Error; 2 3 pub type Result<T> = std::result::Result<T, Error>; 4 5 #[derive(Error, Debug, PartialEq)] 6 #[non_exhaustive] 7 pub enum Error { 8 /// Wrong marshal size. 9 #[error("Wrong marshal size")] 10 WrongMarshalSize, 11 /// Packet lost exceeds maximum amount of packets 12 /// that can possibly be lost. 13 #[error("Invalid total lost count")] 14 InvalidTotalLost, 15 /// Packet contains an invalid header. 16 #[error("Invalid header")] 17 InvalidHeader, 18 /// Packet contains empty compound. 19 #[error("Empty compound packet")] 20 EmptyCompound, 21 /// Invalid first packet in compound packets. First packet 22 /// should either be a SenderReport packet or ReceiverReport 23 #[error("First packet in compound must be SR or RR")] 24 BadFirstPacket, 25 /// CNAME was not defined. 26 #[error("Compound missing SourceDescription with CNAME")] 27 MissingCname, 28 /// Packet was defined before CNAME. 29 #[error("Feedback packet seen before CNAME")] 30 PacketBeforeCname, 31 /// Too many reports. 32 #[error("Too many reports")] 33 TooManyReports, 34 /// Too many chunks. 35 #[error("Too many chunks")] 36 TooManyChunks, 37 /// Too many sources. 38 #[error("too many sources")] 39 TooManySources, 40 /// Packet received is too short. 41 #[error("Packet status chunk must be 2 bytes")] 42 PacketTooShort, 43 /// Buffer is too short. 44 #[error("Buffer too short to be written")] 45 BufferTooShort, 46 /// Wrong packet type. 47 #[error("Wrong packet type")] 48 WrongType, 49 /// SDES received is too long. 50 #[error("SDES must be < 255 octets long")] 51 SdesTextTooLong, 52 /// SDES type is missing. 53 #[error("SDES item missing type")] 54 SdesMissingType, 55 /// Reason is too long. 56 #[error("Reason must be < 255 octets long")] 57 ReasonTooLong, 58 /// Invalid packet version. 59 #[error("Invalid packet version")] 60 BadVersion, 61 /// Invalid padding value. 62 #[error("Invalid padding value")] 63 WrongPadding, 64 /// Wrong feedback message type. 65 #[error("Wrong feedback message type")] 66 WrongFeedbackType, 67 /// Wrong payload type. 68 #[error("Wrong payload type")] 69 WrongPayloadType, 70 /// Header length is too small. 71 #[error("Header length is too small")] 72 HeaderTooSmall, 73 /// Media ssrc was defined as zero. 74 #[error("Media SSRC must be 0")] 75 SsrcMustBeZero, 76 /// Missing REMB identifier. 77 #[error("Missing REMB identifier")] 78 MissingRembIdentifier, 79 /// SSRC number and length mismatches. 80 #[error("SSRC num and length do not match")] 81 SsrcNumAndLengthMismatch, 82 /// Invalid size or start index. 83 #[error("Invalid size or startIndex")] 84 InvalidSizeOrStartIndex, 85 /// Delta exceeds limit. 86 #[error("Delta exceed limit")] 87 DeltaExceedLimit, 88 /// Packet status chunk is not 2 bytes. 89 #[error("Packet status chunk must be 2 bytes")] 90 PacketStatusChunkLength, 91 #[error("Invalid bitrate")] 92 InvalidBitrate, 93 #[error("Wrong chunk type")] 94 WrongChunkType, 95 #[error("Struct contains unexpected member type")] 96 BadStructMemberType, 97 #[error("Cannot read into non-pointer")] 98 BadReadParameter, 99 100 #[error("{0}")] 101 Util(#[from] util::Error), 102 103 #[error("{0}")] 104 Other(String), 105 } 106 107 impl From<Error> for util::Error { from(e: Error) -> Self108 fn from(e: Error) -> Self { 109 util::Error::from_std(e) 110 } 111 } 112 113 impl PartialEq<util::Error> for Error { eq(&self, other: &util::Error) -> bool114 fn eq(&self, other: &util::Error) -> bool { 115 if let Some(down) = other.downcast_ref::<Error>() { 116 return self == down; 117 } 118 false 119 } 120 } 121