diff options
author | Teddy Wing | 2020-08-02 04:53:56 +0200 |
---|---|---|
committer | Teddy Wing | 2020-08-02 04:53:56 +0200 |
commit | a511ff6308a20ac17908a35f42d63c024151da98 (patch) | |
tree | bff1c89f99839cb2af07e1e5e520a488b8a20276 | |
parent | be8dfca975df2b0d0d5b267310bf1c540c873ccc (diff) | |
download | git-suggestion-a511ff6308a20ac17908a35f42d63c024151da98.tar.bz2 |
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.
-rw-r--r-- | src/config.rs | 19 |
1 files 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)), }, } |