1//! Error handling and error types
2use http::Uri;
3use thiserror::Error;
45pub use kube_core::ErrorResponse;
67/// 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:?})")]
18Api(#[source] ErrorResponse),
1920/// Hyper error
21#[cfg(feature = "client")]
22 #[error("HyperError: {0}")]
23HyperError(#[source] hyper::Error),
24/// Service error
25#[cfg(feature = "client")]
26 #[error("ServiceError: {0}")]
27Service(#[source] tower::BoxError),
2829/// Returned when the configured proxy uses an unsupported protocol.
30#[error("configured proxy {proxy_url:?} uses an unsupported protocol")]
31ProxyProtocolUnsupported {
32/// The URL of the proxy.
33proxy_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:?}")]
37ProxyProtocolDisabled {
38/// The URL of the proxy.
39proxy_url: Uri,
40/// The Cargo feature that the proxy protocol requires.
41protocol_feature: &'static str,
42 },
4344/// UTF-8 Error
45#[error("UTF-8 Error: {0}")]
46FromUtf8(#[source] std::string::FromUtf8Error),
4748/// 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")]
52LinesCodecMaxLineLengthExceeded,
5354/// Returned on `std::io::Error` when reading event stream.
55#[error("Error reading events stream: {0}")]
56ReadEvents(#[source] std::io::Error),
5758/// Http based error
59#[error("HttpError: {0}")]
60HttpError(#[source] http::Error),
6162/// Common error case when requesting parsing into own structs
63#[error("Error deserializing response: {0}")]
64SerdeError(#[source] serde_json::Error),
6566/// Failed to build request
67#[error("Failed to build request: {0}")]
68BuildRequest(#[source] kube_core::request::Error),
6970/// Failed to infer config
71#[error("Failed to infer configuration: {0}")]
72InferConfig(#[source] crate::config::InferConfigError),
7374/// Discovery errors
75#[error("Error from discovery: {0}")]
76Discovery(#[source] DiscoveryError),
7778/// Errors from OpenSSL TLS
79#[cfg(feature = "openssl-tls")]
80 #[cfg_attr(docsrs, doc(cfg(feature = "openssl-tls")))]
81 #[error("openssl tls error: {0}")]
82OpensslTls(#[source] crate::client::OpensslTlsError),
8384/// Errors from Rustls TLS
85#[cfg(feature = "rustls-tls")]
86 #[cfg_attr(docsrs, doc(cfg(feature = "rustls-tls")))]
87 #[error("rustls tls error: {0}")]
88RustlsTls(#[source] crate::client::RustlsTlsError),
8990/// Missing TLS stacks when TLS is required
91#[error("TLS required but no TLS stack selected")]
92TlsRequired,
9394/// 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}")]
98UpgradeConnection(#[source] crate::client::UpgradeConnectionError),
99100/// Errors related to client auth
101#[cfg(feature = "client")]
102 #[cfg_attr(docsrs, doc(cfg(feature = "client")))]
103 #[error("auth error: {0}")]
104Auth(#[source] crate::client::AuthError),
105106/// Error resolving resource reference
107#[cfg(feature = "unstable-client")]
108 #[cfg_attr(docsrs, doc(cfg(feature = "unstable-client")))]
109 #[error("Reference resolve error: {0}")]
110RefResolve(String),
111}
112113#[derive(Error, Debug)]
114/// Possible errors when using API [discovery](crate::discovery)
115pub enum DiscoveryError {
116/// Invalid GroupVersion
117#[error("Invalid GroupVersion: {0}")]
118InvalidGroupVersion(String),
119120/// Missing Kind
121#[error("Missing Kind: {0}")]
122MissingKind(String),
123124/// Missing ApiGroup
125#[error("Missing Api Group: {0}")]
126MissingApiGroup(String),
127128/// MissingResource
129#[error("Missing Resource: {0}")]
130MissingResource(String),
131132/// Empty ApiGroup
133#[error("Empty Api Group: {0}")]
134EmptyApiGroup(String),
135}