1 use thiserror::Error; 2 3 use std::io; 4 use std::net; 5 use std::string::FromUtf8Error; 6 7 pub type Result<T> = std::result::Result<T, Error>; 8 9 #[derive(Debug, Error, PartialEq)] 10 #[non_exhaustive] 11 pub enum Error { 12 #[error("mDNS: failed to join multicast group")] 13 ErrJoiningMulticastGroup, 14 #[error("mDNS: connection is closed")] 15 ErrConnectionClosed, 16 #[error("mDNS: context has elapsed")] 17 ErrContextElapsed, 18 #[error("mDNS: config must not be nil")] 19 ErrNilConfig, 20 #[error("parsing/packing of this type isn't available yet")] 21 ErrNotStarted, 22 #[error("parsing/packing of this section has completed")] 23 ErrSectionDone, 24 #[error("parsing/packing of this section is header")] 25 ErrSectionHeader, 26 #[error("insufficient data for base length type")] 27 ErrBaseLen, 28 #[error("insufficient data for calculated length type")] 29 ErrCalcLen, 30 #[error("segment prefix is reserved")] 31 ErrReserved, 32 #[error("too many pointers (>10)")] 33 ErrTooManyPtr, 34 #[error("invalid pointer")] 35 ErrInvalidPtr, 36 #[error("nil resource body")] 37 ErrNilResourceBody, 38 #[error("insufficient data for resource body length")] 39 ErrResourceLen, 40 #[error("segment length too long")] 41 ErrSegTooLong, 42 #[error("zero length segment")] 43 ErrZeroSegLen, 44 #[error("resource length too long")] 45 ErrResTooLong, 46 #[error("too many Questions to pack (>65535)")] 47 ErrTooManyQuestions, 48 #[error("too many Answers to pack (>65535)")] 49 ErrTooManyAnswers, 50 #[error("too many Authorities to pack (>65535)")] 51 ErrTooManyAuthorities, 52 #[error("too many Additionals to pack (>65535)")] 53 ErrTooManyAdditionals, 54 #[error("name is not in canonical format (it must end with a .)")] 55 ErrNonCanonicalName, 56 #[error("character string exceeds maximum length (255)")] 57 ErrStringTooLong, 58 #[error("compressed name in SRV resource data")] 59 ErrCompressedSrv, 60 #[error("empty builder msg")] 61 ErrEmptyBuilderMsg, 62 #[error("{0}")] 63 Io(#[source] IoError), 64 #[error("utf-8 error: {0}")] 65 Utf8(#[from] FromUtf8Error), 66 #[error("parse addr: {0}")] 67 ParseIp(#[from] net::AddrParseError), 68 #[error("{0}")] 69 Other(String), 70 } 71 72 #[derive(Debug, Error)] 73 #[error("io error: {0}")] 74 pub struct IoError(#[from] pub io::Error); 75 76 // Workaround for wanting PartialEq for io::Error. 77 impl PartialEq for IoError { eq(&self, other: &Self) -> bool78 fn eq(&self, other: &Self) -> bool { 79 self.0.kind() == other.0.kind() 80 } 81 } 82 83 impl From<io::Error> for Error { from(e: io::Error) -> Self84 fn from(e: io::Error) -> Self { 85 Error::Io(IoError(e)) 86 } 87 } 88