-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine more errors #696
Refine more errors #696
Conversation
- Add `kube::client::AuthError` (`kube::client::auth::Error`) - Move error variants from `kube::ConfigError` related to client auth - `InvalidBasicAuth` - `InvalidBearerToken` - `UnrefreshableTokenResponse` - `ExecPluginFailed` - `MalformedTokenExpirationDate` - `OAuth` - Add `AuthError::ReadTokenFile` (was `ConfigError::ReadFile`) - Add `AuthError::ParseTokenKey` (was `kube::Error::SerdeError`) - Move `kube::error::OAuthError` to `kube::client::OAuthError` - Add `OAuthError::BuildRequest` (was `kube::Error::HttpError`) - Add `OAuthError::ConcatBuffers` (was `kube::Error::HyperError`) - Change all error under `kube::client::auth` to `kube::client::AuthError` - Add `kube::Error::Auth(kube::client::AuthError)` Signed-off-by: kazk <kazk.dev@gmail.com>
- Move and split `kube::error::ConfigError` into in-cluster and kubeconfig - Add `kube::config::InferConfigError` - Add `kube::config::InClusterError` - Add `kube::config::KubeconfigError` - Remove `kube::Error::InvalidUri` - Change `kube::Error::Kubeconfig` to `kube::Error::InferConfig(kube::config::InferConfigError)` - Change errors in `kube::config` to new `kube::config` errors - Refine errors to preserve context Signed-off-by: kazk <kazk.dev@gmail.com>
Signed-off-by: kazk <kazk.dev@gmail.com>
683860d
to
9bacbcd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a huge batch you've tackled there. Looks great. Really starting to see the benefit now.
The previously daunting src/errors.rs file is looking very small now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some notes.
I need to write a changelog that's not too intimidating.
|
||
/// Failed to exec auth | ||
#[error("failed exec auth: {0}")] | ||
AuthExec(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AuthExec(String)
should be broken down, but we can do that later.
In general, we shouldn't have code like Error::AuthExec(format!("result is not a string {:?}", e))
.
fn load_from_base64_or_file<P: AsRef<Path>>( | ||
value: &Option<String>, | ||
file: &Option<P>, | ||
) -> Result<Vec<u8>, LoadDataError> { | ||
let data = value | ||
.as_deref() | ||
.map(load_from_base64) | ||
.or_else(|| file.as_ref().map(load_from_file)) | ||
.unwrap_or(Err(LoadDataError::NoBase64DataOrFile))?; | ||
Ok(ensure_trailing_newline(data)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The corresponding function looked like the following before this change:
fn data_or_file_with_base64<P: AsRef<Path>>(data: &Option<String>, file: &Option<P>) -> Result<Vec<u8>> {
let mut blob = match (data, file) {
(Some(d), _) => base64::decode(&d)
.map_err(ConfigError::Base64Decode)
.map_err(Error::Kubeconfig),
(_, Some(f)) => read_file(f),
_ => Err(Error::Kubeconfig(ConfigError::NoBase64FileOrData)),
}?;
//Ensure there is a trailing newline in the blob
//Don't bother if the blob is empty
if blob.last().map(|end| *end != b'\n').unwrap_or(false) {
blob.push(b'\n');
}
Ok(blob)
}
I changed the error to a separate LoadDataError
, so we can describe errors like "decoding base64 failed when loading client key" instead of "decoding base64 failed in kubeconfig".
Changed to .map
, .or_else
, .unwrap_or(err)
because I think it makes the behavior more obvious. Not sure if we should allow both value
and file
to be Some
.
Signed-off-by: kazk <kazk.dev@gmail.com>
5557837
to
9c4edc7
Compare
Continuing to refine errors for #688.
kube::ConfigError
tokube::client::AuthError
includingOAuthError
. Change all errors underkube::client::auth
toAuthError
. Addkube::Error::Auth(AuthError)
.kube::ConfigError
tokube::config
and split intoInferConfigError
(error fromConfig::infer
),InClusterError
(in-cluster config errors),KubeconfigError
. No more boxing.kube::config
can be extracted tokube-config
if we want to. Refine errors to preserve context of each error as much as possible. Replacekube::Error::Kubeconfig(ConfigError)
withkube::Error::InferConfig(InferConfigError)
.kube::client::UpgradeConnectionError
, and replace withkube::Error::UpgradeConnection(UpgradeConnectionError)
variant.