quic_rpc_utils/
error.rs

1use std::{
2    error::Error,
3    fmt::{Debug, Display, Formatter, Result as FmtResult},
4    io::Error as IoError,
5    net::AddrParseError,
6    result::Result as StdResult,
7};
8
9#[derive(Debug)]
10pub enum QuicRpcWrapError {
11    AddrParse(AddrParseError),
12    #[cfg(feature = "iroh")]
13    Anyhow(anyhow::Error),
14    BadSink,
15    #[cfg(feature = "hyper")]
16    Hyper(hyper::Error),
17    #[cfg(feature = "hyper")]
18    InvalidUri(hyper::http::uri::InvalidUri),
19    Io(IoError),
20    #[cfg(any(feature = "iroh", feature = "quinn"))]
21    NoInitialCipherSuite(iroh_quinn::crypto::rustls::NoInitialCipherSuite),
22    #[cfg(any(feature = "iroh", feature = "quinn"))]
23    Rcgen(rcgen::Error),
24    ResultAlreadyTakenAway,
25    Recv(String),
26    Request,
27    Response(String),
28    Send(String),
29    #[cfg(any(feature = "iroh", feature = "quinn"))]
30    Rustls(iroh_quinn::rustls::Error),
31}
32
33impl Display for QuicRpcWrapError {
34    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
35        write!(f, "QuicRpcWrapError: ")?;
36        match self {
37            Self::AddrParse(e) => Display::fmt(e, f),
38            #[cfg(feature = "iroh")]
39            Self::Anyhow(e) => Display::fmt(e, f),
40            Self::BadSink => Display::fmt("BadSink", f),
41            #[cfg(feature = "hyper")]
42            Self::Hyper(e) => Display::fmt(e, f),
43            #[cfg(feature = "hyper")]
44            Self::InvalidUri(e) => Display::fmt(e, f),
45            Self::Io(e) => Display::fmt(e, f),
46            #[cfg(any(feature = "iroh", feature = "quinn"))]
47            Self::NoInitialCipherSuite(e) => Display::fmt(e, f),
48            #[cfg(any(feature = "iroh", feature = "quinn"))]
49            Self::Rcgen(e) => Display::fmt(e, f),
50            Self::ResultAlreadyTakenAway => Display::fmt("ResultAlreadyTakenAway", f),
51            Self::Recv(e) => Display::fmt(e, f),
52            Self::Request => Display::fmt("Request", f),
53            Self::Send(e) => Display::fmt(e, f),
54            Self::Response(e) => Display::fmt(e, f),
55            #[cfg(any(feature = "iroh", feature = "quinn"))]
56            Self::Rustls(e) => Display::fmt(e, f),
57        }
58    }
59}
60
61impl Error for QuicRpcWrapError {}
62
63impl From<IoError> for QuicRpcWrapError {
64    fn from(value: IoError) -> Self {
65        Self::Io(value)
66    }
67}
68
69impl From<AddrParseError> for QuicRpcWrapError {
70    fn from(value: AddrParseError) -> Self {
71        Self::AddrParse(value)
72    }
73}
74
75#[cfg(feature = "hyper")]
76impl From<hyper::Error> for QuicRpcWrapError {
77    fn from(value: hyper::Error) -> Self {
78        Self::Hyper(value)
79    }
80}
81
82#[cfg(feature = "hyper")]
83impl From<hyper::http::uri::InvalidUri> for QuicRpcWrapError {
84    fn from(value: hyper::http::uri::InvalidUri) -> Self {
85        Self::InvalidUri(value)
86    }
87}
88
89#[cfg(any(feature = "iroh", feature = "quinn"))]
90impl From<rcgen::Error> for QuicRpcWrapError {
91    fn from(value: rcgen::Error) -> Self {
92        Self::Rcgen(value)
93    }
94}
95
96#[cfg(any(feature = "iroh", feature = "quinn"))]
97impl From<iroh_quinn::rustls::Error> for QuicRpcWrapError {
98    fn from(value: iroh_quinn::rustls::Error) -> Self {
99        Self::Rustls(value)
100    }
101}
102
103#[cfg(any(feature = "iroh", feature = "quinn"))]
104impl From<iroh_quinn::crypto::rustls::NoInitialCipherSuite> for QuicRpcWrapError {
105    fn from(value: iroh_quinn::crypto::rustls::NoInitialCipherSuite) -> Self {
106        Self::NoInitialCipherSuite(value)
107    }
108}
109
110#[cfg(feature = "iroh")]
111impl From<anyhow::Error> for QuicRpcWrapError {
112    fn from(value: anyhow::Error) -> Self {
113        Self::Anyhow(value)
114    }
115}
116
117pub type Result<R> = StdResult<R, QuicRpcWrapError>;