1use std::fmt::{Display, Formatter};
4use std::str::Utf8Error;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug)]
10pub enum Error {
11 InvalidArgs(String),
13
14 InvalidUri(http::uri::InvalidUri),
16
17 IoError(std::io::Error),
19
20 TransportError(tonic::transport::Error),
22
23 GRpcStatus(tonic::Status),
25
26 WatchError(String),
28
29 Utf8Error(Utf8Error),
31
32 LeaseKeepAliveError(String),
34
35 ElectError(String),
37
38 InvalidHeaderValue(http::header::InvalidHeaderValue),
40
41 EndpointError(String),
43
44 #[cfg(feature = "tls-openssl")]
46 OpenSsl(openssl::error::ErrorStack),
47}
48
49impl Display for Error {
50 #[inline]
51 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
52 match self {
53 Error::InvalidArgs(e) => write!(f, "invalid arguments: {}", e),
54 Error::InvalidUri(e) => write!(f, "invalid uri: {}", e),
55 Error::IoError(e) => write!(f, "io error: {}", e),
56 Error::TransportError(e) => write!(f, "transport error: {}", e),
57 Error::GRpcStatus(e) => write!(f, "grpc request error: {}", e),
58 Error::WatchError(e) => write!(f, "watch error: {}", e),
59 Error::Utf8Error(e) => write!(f, "utf8 error: {}", e),
60 Error::LeaseKeepAliveError(e) => write!(f, "lease keep alive error: {}", e),
61 Error::ElectError(e) => write!(f, "election error: {}", e),
62 Error::InvalidHeaderValue(e) => write!(f, "invalid metadata value: {}", e),
63 Error::EndpointError(e) => write!(f, "endpoint error: {}", e),
64 #[cfg(feature = "tls-openssl")]
65 Error::OpenSsl(e) => write!(f, "open ssl error: {}", e),
66 }
67 }
68}
69
70impl std::error::Error for Error {}
71
72impl From<http::uri::InvalidUri> for Error {
73 #[inline]
74 fn from(e: http::uri::InvalidUri) -> Self {
75 Error::InvalidUri(e)
76 }
77}
78
79impl From<std::io::Error> for Error {
80 #[inline]
81 fn from(e: std::io::Error) -> Self {
82 Error::IoError(e)
83 }
84}
85
86impl From<tonic::transport::Error> for Error {
87 #[inline]
88 fn from(e: tonic::transport::Error) -> Self {
89 Error::TransportError(e)
90 }
91}
92
93impl From<tonic::Status> for Error {
94 #[inline]
95 fn from(e: tonic::Status) -> Self {
96 Error::GRpcStatus(e)
97 }
98}
99
100impl From<Utf8Error> for Error {
101 #[inline]
102 fn from(e: Utf8Error) -> Self {
103 Error::Utf8Error(e)
104 }
105}
106
107impl From<http::header::InvalidHeaderValue> for Error {
108 #[inline]
109 fn from(e: http::header::InvalidHeaderValue) -> Self {
110 Error::InvalidHeaderValue(e)
111 }
112}
113
114#[cfg(feature = "tls-openssl")]
115impl From<openssl::error::ErrorStack> for Error {
116 #[inline]
117 fn from(e: openssl::error::ErrorStack) -> Self {
118 Self::OpenSsl(e)
119 }
120}