1use thiserror::Error;
2
3#[derive(Error, Debug)]
5#[non_exhaustive]
6pub enum RpcError {
7 #[error(transparent)]
9 AddrParseError(#[from] std::net::AddrParseError),
10
11 #[error("Could not parse UUID '{0}': {1}")]
13 UuidParseError(String, uuid::Error),
14
15 #[error(transparent)]
17 TransportError(#[from] tonic::transport::Error),
18
19 #[error("Internal Error: {0}")]
21 InternalError(String),
22
23 #[error("No inherent data found in RPC message")]
25 NoInherentData,
26
27 #[error("Could not convert type to or from gRPC to wick.")]
29 TypeConversion,
30
31 #[error("Invalid component kind {0}")]
33 InvalidComponentKind(i32),
34
35 #[error("{0}")]
37 Component(String),
38
39 #[error("Component did not include a supported feature list.")]
41 MissingFeatures,
42
43 #[error("{0}")]
45 Operation(String),
46
47 #[error("Error sending output to channel")]
49 SendError,
50
51 #[error("General error : {0}")]
53 General(String),
54
55 #[error("Deserialization Failed : {0}")]
57 Deserialization(String),
58
59 #[error("Internal Error : {0}")]
61 Internal(&'static str),
62
63 #[error("Configuration for invocation was empty.")]
65 ConfigEmpty,
66
67 #[error("State for invocation was missing.")]
69 StateMissing,
70
71 #[error("Invalid signature")]
73 InvalidSignature,
74}
75
76impl RpcError {
77 pub fn boxed<T: std::fmt::Display>(msg: T) -> Box<Self> {
79 Box::new(RpcError::General(msg.to_string()))
80 }
81}
82
83impl From<tokio::task::JoinError> for RpcError {
84 fn from(e: tokio::task::JoinError) -> Self {
85 RpcError::InternalError(format!("Tokio Error: {}", e))
86 }
87}
88
89impl From<std::io::Error> for RpcError {
90 fn from(e: std::io::Error) -> Self {
91 RpcError::InternalError(format!("IO Error: {}", e))
92 }
93}
94
95impl From<Box<dyn std::error::Error + Send + Sync>> for RpcError {
96 fn from(e: Box<dyn std::error::Error + Send + Sync>) -> Self {
97 RpcError::Component(e.to_string())
98 }
99}
100
101impl From<&str> for RpcError {
102 fn from(e: &str) -> Self {
103 RpcError::General(e.to_owned())
104 }
105}
106
107impl From<String> for RpcError {
108 fn from(e: String) -> Self {
109 RpcError::General(e)
110 }
111}
112
113#[derive(thiserror::Error, Debug)]
115#[non_exhaustive]
116pub enum RpcClientError {
117 #[error("RPC List call failed: {0}")]
119 ListCallFailed(tonic::Status),
120
121 #[error("RPC Invocation failed: {0}")]
123 InvocationFailed(tonic::Status),
124
125 #[error("RPC Stats call failed: {0}")]
127 StatsCallFailed(tonic::Status),
128
129 #[error("RPC response invalid: {0}")]
131 ResponseInvalid(String),
132
133 #[error(transparent)]
135 ConversionFailed(RpcError),
136
137 #[error("Could not convert type to or from gRPC to wick: {0}")]
139 TypeConversion(String),
140
141 #[error("I/O error: {0}")]
143 IO(std::io::Error),
144
145 #[error("Tls error: {0}")]
147 TlsError(tonic::transport::Error),
148
149 #[error("{0}")]
151 ConnectionError(String),
152
153 #[error("unspecified connection error")]
155 UnspecifiedConnectionError,
156
157 #[error("Connection failed: {0}")]
159 ConnectionFailed(String),
160
161 #[error("{0}")]
163 Other(String),
164}
165
166impl From<std::io::Error> for RpcClientError {
167 fn from(e: std::io::Error) -> Self {
168 RpcClientError::IO(e)
169 }
170}
171
172#[cfg(test)]
173mod test {
174
175 use super::*;
176 const fn sync_send<T>()
177 where
178 T: Sync + Send,
179 {
180 }
181
182 #[test]
183 const fn test_sync_send() {
184 sync_send::<RpcError>();
185 sync_send::<RpcClientError>();
186 }
187}