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