Skip to main content

hick_reactor/
error.rs

1//! Public error types surfaced by the async API.
2
3use mdns_proto::{Name, error::RegisterServiceError as ProtoRegisterError};
4
5/// Errors raised while constructing or running an [`Endpoint`](crate::Endpoint).
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum ServerError {
9  /// At least one of IPv4 / IPv6 must be enabled in [`ServerOptions`](crate::ServerOptions).
10  #[error("ServerOptions has neither IPv4 nor IPv6 enabled")]
11  NoFamilyEnabled,
12
13  /// Binding the IPv4 multicast socket failed.
14  #[error("bind v4: {0}")]
15  BindV4(hick_udp::BindError),
16
17  /// Binding the IPv6 multicast socket failed.
18  #[error("bind v6: {0}")]
19  BindV6(hick_udp::BindError),
20
21  /// Wrapping the bound socket as an async UDP socket failed.
22  #[error("wrap socket: {0}")]
23  WrapSocket(std::io::Error),
24
25  /// I/O error during endpoint setup (e.g. setting non-blocking mode).
26  #[error(transparent)]
27  Io(#[from] std::io::Error),
28}
29
30/// Errors raised by [`Endpoint::register_service`](crate::Endpoint::register_service).
31#[derive(Debug, thiserror::Error)]
32#[non_exhaustive]
33pub enum RegisterError {
34  /// A service with the same instance name is already registered.
35  #[error("name already registered: {0}")]
36  NameAlreadyRegistered(Name),
37
38  /// The proto service pool is full.
39  #[error("service pool is full")]
40  StorageFull,
41
42  /// The driver task is no longer running.
43  #[error("endpoint driver is gone")]
44  DriverGone,
45}
46
47impl From<ProtoRegisterError> for RegisterError {
48  fn from(e: ProtoRegisterError) -> Self {
49    match e {
50      ProtoRegisterError::NameAlreadyRegistered(n) => Self::NameAlreadyRegistered(n),
51      ProtoRegisterError::StorageFull(_) => Self::StorageFull,
52      _ => Self::StorageFull,
53    }
54  }
55}
56
57/// Errors raised by [`Endpoint::start_query`](crate::Endpoint::start_query).
58#[derive(Debug, thiserror::Error)]
59#[non_exhaustive]
60pub enum StartQueryError {
61  /// The proto query pool is full.
62  #[error("query pool is full")]
63  StorageFull,
64
65  /// The driver task is no longer running.
66  #[error("endpoint driver is gone")]
67  DriverGone,
68}
69
70/// Errors raised by [`Query::cancel`](crate::Query::cancel) and [`Service::unregister`](crate::Service::unregister).
71#[derive(Debug, thiserror::Error)]
72#[non_exhaustive]
73pub enum CancelError {
74  /// The driver task is no longer running.
75  #[error("endpoint driver is gone")]
76  DriverGone,
77}