Skip to main content

kube_client/
error.rs

1//! Error handling and error types
2use http::Uri;
3use thiserror::Error;
4
5#[allow(deprecated)] pub use kube_core::ErrorResponse;
6pub use kube_core::Status;
7
8/// Possible errors from the [`Client`](crate::Client)
9#[cfg_attr(docsrs, doc(cfg(any(feature = "config", feature = "client"))))]
10#[derive(Error, Debug)]
11pub enum Error {
12    /// ApiError for when things fail
13    ///
14    /// This can be parsed into as an error handling fallback.
15    /// It's also used in `WatchEvent` from watch calls.
16    ///
17    /// It's quite common to get a `410 Gone` when the `resourceVersion` is too old.
18    #[error("ApiError: {0} ({0:?})")]
19    Api(#[source] Box<Status>),
20
21    /// Hyper error
22    #[cfg(feature = "client")]
23    #[error("HyperError: {0}")]
24    HyperError(#[source] hyper::Error),
25    /// Service error
26    #[cfg(feature = "client")]
27    #[error("ServiceError: {0}")]
28    Service(#[source] tower::BoxError),
29
30    /// Returned when the configured proxy uses an unsupported protocol.
31    #[error("configured proxy {proxy_url:?} uses an unsupported protocol")]
32    ProxyProtocolUnsupported {
33        /// The URL of the proxy.
34        proxy_url: Uri,
35    },
36    /// Returned when the configured proxy uses a protocol that requires a Cargo feature that is currently disabled
37    #[error("configured proxy {proxy_url:?} requires the disabled feature {protocol_feature:?}")]
38    ProxyProtocolDisabled {
39        /// The URL of the proxy.
40        proxy_url: Uri,
41        /// The Cargo feature that the proxy protocol requires.
42        protocol_feature: &'static str,
43    },
44
45    /// UTF-8 Error
46    #[error("UTF-8 Error: {0}")]
47    FromUtf8(#[source] std::string::FromUtf8Error),
48
49    /// Returned when failed to find a newline character within max length.
50    /// Only returned by `Client::request_events` and this should never happen as
51    /// the max is `usize::MAX`.
52    #[error("Error finding newline character")]
53    LinesCodecMaxLineLengthExceeded,
54
55    /// Returned on `std::io::Error` when reading event stream.
56    #[error("Error reading events stream: {0}")]
57    ReadEvents(#[source] std::io::Error),
58
59    /// Http based error
60    #[error("HttpError: {0}")]
61    HttpError(#[source] http::Error),
62
63    /// Common error case when requesting parsing into own structs
64    #[error("Error deserializing response: {0}")]
65    SerdeError(#[source] serde_json::Error),
66
67    /// Failed to build request
68    #[error("Failed to build request: {0}")]
69    BuildRequest(#[source] kube_core::request::Error),
70
71    /// Failed to infer config
72    #[error("Failed to infer configuration: {0}")]
73    InferConfig(#[source] crate::config::InferConfigError),
74
75    /// Discovery errors
76    #[error("Error from discovery: {0}")]
77    Discovery(#[source] DiscoveryError),
78
79    /// Errors from OpenSSL TLS
80    #[cfg(feature = "openssl-tls")]
81    #[cfg_attr(docsrs, doc(cfg(feature = "openssl-tls")))]
82    #[error("openssl tls error: {0}")]
83    OpensslTls(#[source] crate::client::OpensslTlsError),
84
85    /// Errors from Rustls TLS
86    #[cfg(feature = "rustls-tls")]
87    #[cfg_attr(docsrs, doc(cfg(feature = "rustls-tls")))]
88    #[error("rustls tls error: {0}")]
89    RustlsTls(#[source] crate::client::RustlsTlsError),
90
91    /// Missing TLS stacks when TLS is required
92    #[error("TLS required but no TLS stack selected")]
93    TlsRequired,
94
95    /// Failed to upgrade to a WebSocket connection
96    #[cfg(feature = "ws")]
97    #[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
98    #[error("failed to upgrade to a WebSocket connection: {0}")]
99    UpgradeConnection(#[source] crate::client::UpgradeConnectionError),
100
101    /// Errors related to client auth
102    #[cfg(feature = "client")]
103    #[cfg_attr(docsrs, doc(cfg(feature = "client")))]
104    #[error("auth error: {0}")]
105    Auth(#[source] crate::client::AuthError),
106
107    /// Error resolving resource reference
108    #[cfg(feature = "unstable-client")]
109    #[cfg_attr(docsrs, doc(cfg(feature = "unstable-client")))]
110    #[error("Reference resolve error: {0}")]
111    RefResolve(String),
112
113    /// Failed to infer custom configuration
114    #[error("Failed to infer provided configuration: {0}")]
115    InferKubeconfig(#[from] crate::config::KubeconfigError),
116}
117
118#[derive(Error, Debug)]
119/// Possible errors when using API [discovery](crate::discovery)
120pub enum DiscoveryError {
121    /// Invalid GroupVersion
122    #[error("Invalid GroupVersion: {0}")]
123    InvalidGroupVersion(String),
124
125    /// Missing Kind
126    #[error("Missing Kind: {0}")]
127    MissingKind(String),
128
129    /// Missing ApiGroup
130    #[error("Missing Api Group: {0}")]
131    MissingApiGroup(String),
132
133    /// MissingResource
134    #[error("Missing Resource: {0}")]
135    MissingResource(String),
136
137    /// Empty ApiGroup
138    #[error("Empty Api Group: {0}")]
139    EmptyApiGroup(String),
140}