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