spiffe/
error.rs

1//! Error types for Workload API client operations.
2
3use crate::{JwtBundleError, JwtSvidError, SpiffeIdError, X509BundleError, X509SvidError};
4use thiserror::Error;
5use url::ParseError;
6
7/// Errors produced by the Workload API client.
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum GrpcClientError {
11    /// `SPIFFE_ENDPOINT_SOCKET` is not set.
12    #[error("missing SPIFFE_ENDPOINT_SOCKET")]
13    MissingEndpointSocketPath,
14
15    /// The Workload API returned an empty response.
16    #[error("empty Workload API response")]
17    EmptyResponse,
18
19    /// The endpoint socket path is invalid.
20    #[error("invalid endpoint socket path")]
21    InvalidEndpointSocketPath(#[from] SocketPathError),
22
23    /// Failed to parse an X.509 SVID from the Workload API response.
24    #[error("x509 svid parse error")]
25    X509Svid(#[from] X509SvidError),
26
27    /// Failed to parse a JWT-SVID from the Workload API response.
28    #[error("jwt svid parse error")]
29    JwtSvid(#[from] JwtSvidError),
30
31    /// Failed to parse an X.509 bundle from the Workload API response.
32    #[error("x509 bundle parse error")]
33    X509Bundle(#[from] X509BundleError),
34
35    /// Failed to parse a JWT bundle from the Workload API response.
36    #[error("jwt bundle parse error")]
37    JwtBundle(#[from] JwtBundleError),
38
39    /// Failed to parse a SPIFFE identifier from the Workload API response.
40    #[error("spiffe id parse error")]
41    SpiffeId(#[from] SpiffeIdError),
42
43    /// gRPC status returned by the Workload API.
44    #[cfg(feature = "workload-api")]
45    #[error("gRPC status: {0}")]
46    Grpc(#[from] tonic::Status),
47
48    /// Transport error while connecting to the Workload API.
49    #[cfg(feature = "workload-api")]
50    #[error("gRPC transport error: {0}")]
51    Transport(#[from] tonic::transport::Error),
52}
53
54/// Errors related to validating `SPIFFE_ENDPOINT_SOCKET`.
55#[derive(Debug, Error, PartialEq, Clone)]
56#[non_exhaustive]
57pub enum SocketPathError {
58    /// Scheme must be `unix` or `tcp`.
59    #[error("endpoint socket URI scheme must be tcp:// or unix://")]
60    InvalidScheme,
61
62    /// `unix://` URIs must include a path.
63    #[error("unix:// endpoint socket URI must include a path")]
64    UnixAddressEmptyPath,
65
66    /// `tcp://` URIs must not include a path component.
67    #[error("tcp:// endpoint socket URI must not include a path")]
68    TcpAddressNonEmptyPath,
69
70    /// URI must not include query values.
71    #[error("endpoint socket URI must not include query values")]
72    HasQueryValues,
73
74    /// URI must not include a fragment.
75    #[error("endpoint socket URI must not include a fragment")]
76    HasFragment,
77
78    /// URI must not include user info.
79    #[error("endpoint socket URI must not include user info")]
80    HasUserInfo,
81
82    /// `tcp://` URIs must include a host.
83    #[error("tcp:// endpoint socket URI must include a host")]
84    TcpEmptyHost,
85
86    /// `tcp://` URIs must include an IP:port.
87    #[error("tcp:// endpoint socket URI host must be an IP:port")]
88    TcpAddressNoIpPort,
89
90    /// URI parsing failed.
91    #[error("endpoint socket is not a valid URI")]
92    Parse(#[from] ParseError),
93}