From c890082d52f60e210e91f0e8a114034474cbc5bf Mon Sep 17 00:00:00 2001 From: clux Date: Sat, 27 Feb 2021 21:34:30 +0000 Subject: [PATCH] swap naked .expect for an error --- kube/src/config/file_config.rs | 3 ++- kube/src/error.rs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/kube/src/config/file_config.rs b/kube/src/config/file_config.rs index 32943f709..6c8a81a0f 100644 --- a/kube/src/config/file_config.rs +++ b/kube/src/config/file_config.rs @@ -186,7 +186,8 @@ impl Kubeconfig { merged_docs = Some(config); } } - Ok(merged_docs.expect("Need at least one yaml document in KUBECONFIG file")) + let config = merged_docs.ok_or_else(|| ConfigError::EmptyKubeconfig(path.as_ref().to_path_buf()))?; + Ok(config) } /// Read a Config from `KUBECONFIG` or the the default location. diff --git a/kube/src/error.rs b/kube/src/error.rs index 1a4d83632..d14905d6a 100644 --- a/kube/src/error.rs +++ b/kube/src/error.rs @@ -185,6 +185,9 @@ pub enum ConfigError { #[error("Failed to parse Kubeconfig YAML: {0}")] ParseYaml(#[source] serde_yaml::Error), + #[error("Failed to find a single YAML document in Kubeconfig: {0}")] + EmptyKubeconfig(PathBuf), + #[error("Unable to run auth exec: {0}")] AuthExecStart(#[source] std::io::Error), #[error("Auth exec command '{cmd}' failed with status {status}: {out:?}")]