memberlist_quic/
error.rs

1use super::*;
2
3/// Errors that can occur when using [`QuicTransport`].
4#[derive(thiserror::Error)]
5pub enum QuicTransportError<A: AddressResolver> {
6  /// Returns when there is no explicit advertise address and no private IP address found.
7  #[error("no private IP address found, and explicit IP not provided")]
8  NoPrivateIP,
9  /// Returns when there is no bind address provided.
10  #[error("at least one bind address is required")]
11  EmptyBindAddresses,
12  /// Returns when the ip is blocked.
13  #[error("the ip {0} is blocked")]
14  BlockedIp(IpAddr),
15  /// Returns when the listener fails to bind.
16  #[error("failed to start listener on {0}: {1}")]
17  Listen(SocketAddr, std::io::Error),
18  /// Returns when the failed to create a resolver for the transport.
19  #[error("failed to create resolver: {0}")]
20  Resolver(A::Error),
21  /// Returns when we fail to resolve an address.
22  #[error("failed to resolve address {addr}: {err}")]
23  Resolve {
24    /// The address we failed to resolve.
25    addr: A::Address,
26    /// The error that occurred.
27    err: A::Error,
28  },
29  /// Returns when the using Wire to encode/decode message.
30  #[error(transparent)]
31  Io(#[from] std::io::Error),
32  /// Returns when the packet is too large.
33  #[error("packet too large, the maximum packet can be sent is 65535, got {0}")]
34  PacketTooLarge(usize),
35  /// Returns when there is a custom error.
36  #[error("{0}")]
37  Custom(std::borrow::Cow<'static, str>),
38}
39
40impl<A: AddressResolver> core::fmt::Debug for QuicTransportError<A> {
41  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42    core::fmt::Display::fmt(&self, f)
43  }
44}
45
46impl<A> TransportError for QuicTransportError<A>
47where
48  A: AddressResolver,
49  A::Address: Send + Sync + 'static,
50{
51  fn is_remote_failure(&self) -> bool {
52    use std::io::ErrorKind;
53
54    match &self {
55      Self::Io(e) => matches!(
56        e.kind(),
57        ErrorKind::ConnectionRefused
58          | ErrorKind::ConnectionReset
59          | ErrorKind::ConnectionAborted
60          | ErrorKind::BrokenPipe
61          | ErrorKind::TimedOut
62          | ErrorKind::NotConnected
63      ),
64      _ => false,
65    }
66  }
67
68  fn custom(err: std::borrow::Cow<'static, str>) -> Self {
69    Self::Custom(err)
70  }
71}