kube_client/
error.rs

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