comparison src/error.rs @ 13:f740dadd2948

Added enable_systemd feature This feature makes systemd support optional, on by default. While it may seem strange that this feature exists, it makes sense for authors of applications who want to make systemd optional. Thanks to this feature the interface stays the same, it just fails to parse `systemd://` addresses with a helpful error message.
author Martin Habovstiak <martin.habovstiak@gmail.com>
date Thu, 03 Dec 2020 16:34:09 +0100
parents a7893294e9b2
children bc76507dd878
comparison
equal deleted inserted replaced
12:4479770c2275 13:f740dadd2948
17 17
18 #[derive(Debug, Error)] 18 #[derive(Debug, Error)]
19 pub(crate) enum ParseErrorInner { 19 pub(crate) enum ParseErrorInner {
20 #[error("failed to parse socket address")] 20 #[error("failed to parse socket address")]
21 ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError), 21 ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError),
22 #[cfg(linux)] 22 #[cfg(all(linux, feature = "enable_systemd"))]
23 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] 23 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")]
24 InvalidCharacter { string: String, c: char, pos: usize, }, 24 InvalidCharacter { string: String, c: char, pos: usize, },
25 #[cfg(linux)] 25 #[cfg(all(linux, feature = "enable_systemd"))]
26 #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")] 26 #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")]
27 LongSocketName { string: String, len: usize, }, 27 LongSocketName { string: String, len: usize, },
28 #[cfg(not(linux))] 28 #[cfg(not(all(linux, feature = "enable_systemd")))]
29 #[error("can't parse {0} because systemd is not supported on this operating system")] 29 #[cfg_attr(not(linux), error("can't parse {0} because systemd is not supported on this operating system"))]
30 #[cfg_attr(linux, error("can't parse {0} because systemd support was disabled during build"))]
30 SystemdUnsupported(String), 31 SystemdUnsupported(String),
31 } 32 }
32 33
33 /// Error that can occur during parsing of `SocketAddr` from a `OsStr`/`OsString` 34 /// Error that can occur during parsing of `SocketAddr` from a `OsStr`/`OsString`
34 /// 35 ///
63 pub(crate) enum BindErrorInner { 64 pub(crate) enum BindErrorInner {
64 #[error("failed to bind {addr}")] 65 #[error("failed to bind {addr}")]
65 BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, }, 66 BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, },
66 #[error("failed to bind {addr}")] 67 #[error("failed to bind {addr}")]
67 BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, }, 68 BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, },
68 #[cfg(linux)] 69 #[cfg(all(linux, feature = "enable_systemd"))]
69 #[error("failed to receive descriptors with names")] 70 #[error("failed to receive descriptors with names")]
70 ReceiveDescriptors(#[source] crate::systemd_sockets::Error), 71 ReceiveDescriptors(#[source] crate::systemd_sockets::Error),
71 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")] 72 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")]
72 #[cfg(linux)] 73 #[cfg(all(linux, feature = "enable_systemd"))]
73 MissingDescriptor(String), 74 MissingDescriptor(String),
74 #[error("the systemd socket {0} is not an internet socket")] 75 #[error("the systemd socket {0} is not an internet socket")]
75 #[cfg(linux)] 76 #[cfg(all(linux, feature = "enable_systemd"))]
76 NotInetSocket(String), 77 NotInetSocket(String),
77 } 78 }
78 79
79 /// Error that can happen when binding Tokio socket. 80 /// Error that can happen when binding Tokio socket.
80 /// 81 ///