From a511ff6308a20ac17908a35f42d63c024151da98 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 2 Aug 2020 04:53:56 +0200 Subject: config::Error::EnvVar: Include the variable name in the error message The source error's message doesn't include the name. Ensure we print the name of the variable we're trying to get so that users know which one is missing. --- src/config.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index cd81d43..222c69a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,8 +14,11 @@ pub enum Error { #[error("Unable to parse arguments: {0}")] Opts(#[from] getopts::Fail), - #[error("Error getting environment variable")] - EnvVar(#[from] env::VarError), + #[error("Error getting environment variable '{var}'")] + EnvVar { + source: env::VarError, + var: String, + }, #[error(transparent)] OwnerRepo(#[from] owner_repo::Error), @@ -62,9 +65,15 @@ impl Config { Some(t) => Ok(t), None => match git_config.get_string(&git_config_key("githubToken")) { - Err(e) if e.code() == git2::ErrorCode::NotFound => - env::var("GITHUB_TOKEN") - .map_err(|e| Error::EnvVar(e)), + Err(e) if e.code() == git2::ErrorCode::NotFound => { + let key = "GITHUB_TOKEN"; + + env::var(key) + .map_err(|e| Error::EnvVar { + source: e, + var: key.to_owned(), + }) + }, r => r.map_err(|e| Error::Git(e)), }, } -- cgit v1.2.3