Mercurial > crates > systemd-socket
comparison src/error.rs @ 28:cfef4593e207
Run `cargo fmt`.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 19 Apr 2025 01:33:50 -0400 |
parents | 1941e9d9819c |
children |
comparison
equal
deleted
inserted
replaced
27:85b0f4a7303d | 28:cfef4593e207 |
---|---|
1 //! Error types that can occur when dealing with `SocketAddr` | 1 //! Error types that can occur when dealing with `SocketAddr` |
2 //! | 2 //! |
3 //! This module separates the error types from root module to avoid clutter. | 3 //! This module separates the error types from root module to avoid clutter. |
4 | 4 |
5 | |
6 use thiserror::Error; | |
7 use std::fmt; | 5 use std::fmt; |
8 use std::io; | 6 use std::io; |
7 use thiserror::Error; | |
9 | 8 |
10 /// Error returned when the library initialization fails. | 9 /// Error returned when the library initialization fails. |
11 #[derive(Debug)] | 10 #[derive(Debug)] |
12 pub struct InitError(pub(crate) InitErrorInner); | 11 pub struct InitError(pub(crate) InitErrorInner); |
13 | 12 |
44 pub(crate) enum ParseErrorInner { | 43 pub(crate) enum ParseErrorInner { |
45 #[error("failed to parse socket address")] | 44 #[error("failed to parse socket address")] |
46 ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError), | 45 ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError), |
47 #[cfg(all(target_os = "linux", feature = "enable_systemd"))] | 46 #[cfg(all(target_os = "linux", feature = "enable_systemd"))] |
48 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] | 47 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] |
49 InvalidCharacter { string: String, c: char, pos: usize, }, | 48 InvalidCharacter { string: String, c: char, pos: usize }, |
50 #[cfg(all(target_os = "linux", feature = "enable_systemd"))] | 49 #[cfg(all(target_os = "linux", feature = "enable_systemd"))] |
51 #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")] | 50 #[error( |
52 LongSocketName { string: String, len: usize, }, | 51 "systemd socket name {string} is {len} characters long which is more than the limit 255" |
52 )] | |
53 LongSocketName { string: String, len: usize }, | |
53 #[cfg(not(all(target_os = "linux", feature = "enable_systemd")))] | 54 #[cfg(not(all(target_os = "linux", feature = "enable_systemd")))] |
54 #[cfg_attr(not(target_os = "linux"), error("can't parse {0} because systemd is not supported on this operating system"))] | 55 #[cfg_attr( |
55 #[cfg_attr(target_os = "linux", error("can't parse {0} because systemd support was disabled during build"))] | 56 not(target_os = "linux"), |
57 error("can't parse {0} because systemd is not supported on this operating system") | |
58 )] | |
59 #[cfg_attr( | |
60 target_os = "linux", | |
61 error("can't parse {0} because systemd support was disabled during build") | |
62 )] | |
56 SystemdUnsupported(String), | 63 SystemdUnsupported(String), |
57 } | 64 } |
58 | 65 |
59 /// Error that can occur during parsing of `SocketAddr` from a `OsStr`/`OsString` | 66 /// Error that can occur during parsing of `SocketAddr` from a `OsStr`/`OsString` |
60 /// | 67 /// |
86 pub struct BindError(#[from] pub(crate) BindErrorInner); | 93 pub struct BindError(#[from] pub(crate) BindErrorInner); |
87 | 94 |
88 #[derive(Debug, Error)] | 95 #[derive(Debug, Error)] |
89 pub(crate) enum BindErrorInner { | 96 pub(crate) enum BindErrorInner { |
90 #[error("failed to bind {addr}")] | 97 #[error("failed to bind {addr}")] |
91 BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, }, | 98 BindFailed { |
99 addr: std::net::SocketAddr, | |
100 #[source] | |
101 error: io::Error, | |
102 }, | |
92 #[error("failed to bind {addr}")] | 103 #[error("failed to bind {addr}")] |
93 BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, }, | 104 BindOrResolvFailed { |
105 addr: crate::resolv_addr::ResolvAddr, | |
106 #[source] | |
107 error: io::Error, | |
108 }, | |
94 #[cfg(all(target_os = "linux", feature = "enable_systemd"))] | 109 #[cfg(all(target_os = "linux", feature = "enable_systemd"))] |
95 #[error("failed to receive descriptors with names")] | 110 #[error("failed to receive descriptors with names")] |
96 ReceiveDescriptors(#[source] crate::systemd_sockets::Error), | 111 ReceiveDescriptors(#[source] crate::systemd_sockets::Error), |
97 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")] | 112 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")] |
98 #[cfg(all(target_os = "linux", feature = "enable_systemd"))] | 113 #[cfg(all(target_os = "linux", feature = "enable_systemd"))] |
127 pub struct TokioConversionError { | 142 pub struct TokioConversionError { |
128 pub(crate) addr: crate::SocketAddrInner, | 143 pub(crate) addr: crate::SocketAddrInner, |
129 #[source] | 144 #[source] |
130 pub(crate) error: io::Error, | 145 pub(crate) error: io::Error, |
131 } | 146 } |
132 |