1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::fmt::{Display, Formatter};
use std::str::Utf8Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
InvalidArgs(String),
InvalidUri(http::uri::InvalidUri),
IoError(std::io::Error),
TransportError(tonic::transport::Error),
GRpcStatus(tonic::Status),
WatchError(String),
Utf8Error(Utf8Error),
LeaseKeepAliveError(String),
ElectError(String),
InvalidHeaderValue(http::header::InvalidHeaderValue),
}
impl Display for Error {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::InvalidArgs(e) => write!(f, "invalid arguments: {}", e),
Error::InvalidUri(e) => write!(f, "invalid uri: {}", e),
Error::IoError(e) => write!(f, "io error: {}", e),
Error::TransportError(e) => write!(f, "transport error: {}", e),
Error::GRpcStatus(e) => write!(f, "grpc request error: {}", e),
Error::WatchError(e) => write!(f, "watch error: {}", e),
Error::Utf8Error(e) => write!(f, "utf8 error: {}", e),
Error::LeaseKeepAliveError(e) => write!(f, "lease keep alive error: {}", e),
Error::ElectError(e) => write!(f, "election error: {}", e),
Error::InvalidHeaderValue(e) => write!(f, "invalid metadata value: {}", e),
}
}
}
impl std::error::Error for Error {}
impl From<http::uri::InvalidUri> for Error {
#[inline]
fn from(e: http::uri::InvalidUri) -> Self {
Error::InvalidUri(e)
}
}
impl From<std::io::Error> for Error {
#[inline]
fn from(e: std::io::Error) -> Self {
Error::IoError(e)
}
}
impl From<tonic::transport::Error> for Error {
#[inline]
fn from(e: tonic::transport::Error) -> Self {
Error::TransportError(e)
}
}
impl From<tonic::Status> for Error {
#[inline]
fn from(e: tonic::Status) -> Self {
Error::GRpcStatus(e)
}
}
impl From<Utf8Error> for Error {
#[inline]
fn from(e: Utf8Error) -> Self {
Error::Utf8Error(e)
}
}
impl From<http::header::InvalidHeaderValue> for Error {
#[inline]
fn from(e: http::header::InvalidHeaderValue) -> Self {
Error::InvalidHeaderValue(e)
}
}