zingo_netutils/error.rs
1//! Error types for the [`Indexer`](super::Indexer) and
2//! `TransparentIndexer` traits.
3//!
4/// Callers can depend on:
5/// - `InvalidScheme` and `InvalidAuthority` are deterministic — retrying
6/// with the same URI will always fail.
7/// - `Transport` wraps a [`tonic::transport::Error`] and may be transient
8/// (e.g. DNS resolution, TCP connect timeout). Retrying may succeed.
9///
10/// ```
11/// use zingo_netutils::GetClientError;
12///
13/// let e = GetClientError::InvalidScheme;
14/// assert_eq!(e.to_string(), "bad uri: invalid scheme");
15///
16/// let e = GetClientError::InvalidAuthority;
17/// assert_eq!(e.to_string(), "bad uri: invalid authority");
18///
19/// // Transport variant accepts From<tonic::transport::Error>
20/// let _: fn(tonic::transport::Error) -> GetClientError = GetClientError::from;
21/// ```
22#[derive(Debug, thiserror::Error)]
23pub enum GetClientError {
24 #[error("bad uri: invalid scheme")]
25 InvalidScheme,
26
27 #[error("bad uri: invalid authority")]
28 InvalidAuthority,
29
30 #[error(transparent)]
31 Transport(#[from] tonic::transport::Error),
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn transport_from_conversion() {
40 // Verify the From impl exists at compile time.
41 let _: fn(tonic::transport::Error) -> GetClientError = GetClientError::from;
42 }
43}