Skip to content

Commit

Permalink
swap naked .expect for an error
Browse files Browse the repository at this point in the history
  • Loading branch information
clux committed Feb 27, 2021
1 parent 451429c commit c890082
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kube/src/config/file_config.rs
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions kube/src/error.rs
Expand Up @@ -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:?}")]
Expand Down

0 comments on commit c890082

Please sign in to comment.