maestro_rs/error.rs
1use std::{
2 io,
3 net::{IpAddr, SocketAddr},
4};
5
6/// Errors produced by `maestro-rs`.
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 /// The interface name is empty or contains a NUL byte.
11 #[error("invalid network interface name `{0}`")]
12 InvalidInterfaceName(String),
13
14 /// No interface with this name exists on the system.
15 #[error("network interface `{0}` not found")]
16 InterfaceNotFound(String),
17
18 /// [`BindMode::Interface`](crate::BindMode::Interface) was requested but
19 /// the interface has no IP address.
20 #[error("network interface `{0}` has no IP address to bind to")]
21 NoInterfaceAddress(String),
22
23 /// A socket could not be bound to `addr`.
24 #[error("failed to bind {addr}")]
25 Bind {
26 /// The address that could not be bound.
27 addr: SocketAddr,
28 /// The underlying OS error.
29 #[source]
30 source: io::Error,
31 },
32
33 /// A UDP socket could not join a multicast group.
34 #[error("failed to join multicast group {group}")]
35 JoinMulticast {
36 /// The multicast group.
37 group: IpAddr,
38 /// The underlying OS error.
39 #[source]
40 source: io::Error,
41 },
42
43 /// An internal worker task panicked or was cancelled.
44 #[error("service worker task failed")]
45 Task(#[from] tokio::task::JoinError),
46
47 /// Every registered service stopped after exhausting its
48 /// [`RestartPolicy`](crate::RestartPolicy) before shutdown was requested.
49 #[error("all services stopped after exhausting their restart policy")]
50 AllServicesFailed,
51
52 /// Any other I/O error.
53 #[error(transparent)]
54 Io(#[from] io::Error),
55}
56
57/// Shorthand for `Result<T, maestro_rs::Error>`.
58pub type Result<T, E = Error> = std::result::Result<T, E>;