Mercurial > crates > systemd-socket
annotate src/error.rs @ 8:372afb9a700f
Prolong waiting for bind
It looks like 1 second of waiting is still too low.
author | Martin Habovstiak <martin.habovstiak@gmail.com> |
---|---|
date | Fri, 27 Nov 2020 16:33:47 +0100 |
parents | a7893294e9b2 |
children | f740dadd2948 |
rev | line source |
---|---|
0 | 1 //! Error types that can occur when dealing with `SocketAddr` |
2 //! | |
3 //! This module separates the error types from root module to avoid clutter. | |
4 | |
5 | |
6 use thiserror::Error; | |
7 use std::io; | |
8 | |
9 /// Error that can occur during parsing of `SocketAddr` from a string | |
10 /// | |
11 /// This encapsulates possible errors that can occur when parsing the input. | |
12 /// It is currently opaque because the representation is not certain yet. | |
13 /// It can be displayed using the standard `Error` trait. | |
14 #[derive(Debug, Error)] | |
15 #[error(transparent)] | |
16 pub struct ParseError(#[from] pub(crate) ParseErrorInner); | |
17 | |
18 #[derive(Debug, Error)] | |
19 pub(crate) enum ParseErrorInner { | |
20 #[error("failed to parse socket address")] | |
4
66c0e10c89fc
Support resolving hostnames
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
2
diff
changeset
|
21 ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError), |
6
a7893294e9b2
Make the crate compilable on non-linux systems
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
4
diff
changeset
|
22 #[cfg(linux)] |
0 | 23 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] |
2
cabc4aafdd85
Added length check and a few tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
0
diff
changeset
|
24 InvalidCharacter { string: String, c: char, pos: usize, }, |
6
a7893294e9b2
Make the crate compilable on non-linux systems
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
4
diff
changeset
|
25 #[cfg(linux)] |
2
cabc4aafdd85
Added length check and a few tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
0
diff
changeset
|
26 #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")] |
cabc4aafdd85
Added length check and a few tests
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
0
diff
changeset
|
27 LongSocketName { string: String, len: usize, }, |
6
a7893294e9b2
Make the crate compilable on non-linux systems
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
4
diff
changeset
|
28 #[cfg(not(linux))] |
a7893294e9b2
Make the crate compilable on non-linux systems
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
4
diff
changeset
|
29 #[error("can't parse {0} because systemd is not supported on this operating system")] |
a7893294e9b2
Make the crate compilable on non-linux systems
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
4
diff
changeset
|
30 SystemdUnsupported(String), |
0 | 31 } |
32 | |
33 /// Error that can occur during parsing of `SocketAddr` from a `OsStr`/`OsString` | |
34 /// | |
35 /// As opposed to parsing from `&str` or `String`, parsing from `OsStr` can fail due to one more | |
36 /// reason: invalid UTF-8. This error type expresses this possibility and is returned whenever such | |
37 /// conversion is attempted. It is not opaque because the possible variants are pretty much | |
38 /// certain, but it may contain `ParseError` which is opaque. | |
39 /// | |
40 /// This error can be displayed using standard `Error` trait. | |
41 /// See `ParseError` for more information. | |
42 #[derive(Debug, Error)] | |
43 pub enum ParseOsStrError { | |
44 /// The input was not a valid UTF-8 string | |
45 #[error("the address is not a valid UTF-8 string")] | |
46 InvalidUtf8, | |
47 /// The input was a valid UTF-8 string but the address was invalid | |
48 #[error(transparent)] | |
49 InvalidAddress(#[from] ParseError), | |
50 } | |
51 | |
52 /// Error that can occur during binding of a socket | |
53 /// | |
54 /// This encapsulates possible errors that can occur when binding a socket or receiving a socket | |
55 /// from systemd. | |
56 /// It is currently opaque because the representation is not certain yet. | |
57 /// It can be displayed using the standard `Error` trait. | |
58 #[derive(Debug, Error)] | |
59 #[error(transparent)] | |
60 pub struct BindError(#[from] pub(crate) BindErrorInner); | |
61 | |
62 #[derive(Debug, Error)] | |
63 pub(crate) enum BindErrorInner { | |
64 #[error("failed to bind {addr}")] | |
65 BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, }, | |
4
66c0e10c89fc
Support resolving hostnames
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
2
diff
changeset
|
66 #[error("failed to bind {addr}")] |
66c0e10c89fc
Support resolving hostnames
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
2
diff
changeset
|
67 BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, }, |
6
a7893294e9b2
Make the crate compilable on non-linux systems
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
4
diff
changeset
|
68 #[cfg(linux)] |
0 | 69 #[error("failed to receive descriptors with names")] |
70 ReceiveDescriptors(#[source] crate::systemd_sockets::Error), | |
71 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")] | |
6
a7893294e9b2
Make the crate compilable on non-linux systems
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
4
diff
changeset
|
72 #[cfg(linux)] |
0 | 73 MissingDescriptor(String), |
74 #[error("the systemd socket {0} is not an internet socket")] | |
6
a7893294e9b2
Make the crate compilable on non-linux systems
Martin Habovstiak <martin.habovstiak@gmail.com>
parents:
4
diff
changeset
|
75 #[cfg(linux)] |
0 | 76 NotInetSocket(String), |
77 } | |
78 | |
79 /// Error that can happen when binding Tokio socket. | |
80 /// | |
81 /// As opposed to `std` and `async_std` sockets, tokio sockets can fail to convert. | |
82 /// This error type expresses this possibility. | |
83 #[cfg(any(feature = "tokio_0_2", feature = "tokio_0_3"))] | |
84 #[derive(Debug, Error)] | |
85 #[error(transparent)] | |
86 pub enum TokioBindError { | |
87 /// Either binding of socket or receiving systemd socket failed | |
88 Bind(#[from] BindError), | |
89 /// Conversion from std `std::net::TcpListener` to `tokio::net::TcpListener` failed | |
90 Convert(#[from] TokioConversionError), | |
91 } | |
92 | |
93 /// Error that can happen when converting Tokio socket. | |
94 /// | |
95 /// As opposed to `std` and `async_std` sockets, tokio sockets can fail to convert. | |
96 /// This error type encapsulates conversion error together with additional information so that it | |
97 /// can be displayed nicely. The encapsulation also allows for future-proofing. | |
98 #[cfg(any(feature = "tokio_0_2", feature = "tokio_0_3"))] | |
99 #[derive(Debug, Error)] | |
100 #[error("failed to convert std socket {addr} into tokio socket")] | |
101 pub struct TokioConversionError { | |
102 pub(crate) addr: crate::SocketAddrInner, | |
103 #[source] | |
104 pub(crate) error: io::Error, | |
105 } | |
106 |