1 use thiserror::Error; 2 3 use std::io; 4 use std::num::ParseIntError; 5 use std::string::FromUtf8Error; 6 use substring::Substring; 7 8 pub type Result<T> = std::result::Result<T, Error>; 9 10 #[derive(Debug, Error, PartialEq)] 11 #[non_exhaustive] 12 pub enum Error { 13 #[error("codec not found")] 14 CodecNotFound, 15 #[error("missing whitespace")] 16 MissingWhitespace, 17 #[error("missing colon")] 18 MissingColon, 19 #[error("payload type not found")] 20 PayloadTypeNotFound, 21 #[error("{0}")] 22 Io(#[source] IoError), 23 #[error("utf-8 error: {0}")] 24 Utf8(#[from] FromUtf8Error), 25 #[error("SdpInvalidSyntax: {0}")] 26 SdpInvalidSyntax(String), 27 #[error("SdpInvalidValue: {0}")] 28 SdpInvalidValue(String), 29 #[error("sdp: empty time_descriptions")] 30 SdpEmptyTimeDescription, 31 #[error("parse int: {0}")] 32 ParseInt(#[from] ParseIntError), 33 #[error("parse url: {0}")] 34 ParseUrl(#[from] url::ParseError), 35 #[error("parse extmap: {0}")] 36 ParseExtMap(String), 37 #[error("{} --> {} <-- {}", .s.substring(0,*.p), .s.substring(*.p, *.p+1), .s.substring(*.p+1, .s.len()))] 38 SyntaxError { s: String, p: usize }, 39 } 40 41 #[derive(Debug, Error)] 42 #[error("io error: {0}")] 43 pub struct IoError(#[from] pub io::Error); 44 45 // Workaround for wanting PartialEq for io::Error. 46 impl PartialEq for IoError { eq(&self, other: &Self) -> bool47 fn eq(&self, other: &Self) -> bool { 48 self.0.kind() == other.0.kind() 49 } 50 } 51 52 impl From<io::Error> for Error { from(e: io::Error) -> Self53 fn from(e: io::Error) -> Self { 54 Error::Io(IoError(e)) 55 } 56 } 57