Skip to content

Commit

Permalink
Merge pull request #26 from dtolnay/tryexists
Browse files Browse the repository at this point in the history
Eliminate try_exists call prior to reading hosts.yml
  • Loading branch information
dtolnay committed Apr 5, 2024
2 parents 4a84332 + 39612a4 commit e5338b7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions gh-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde_derive::Deserialize;
use std::env;
use std::fmt::{self, Debug, Display};
use std::fs;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use std::process::Command;

Expand Down Expand Up @@ -94,15 +95,15 @@ pub fn get() -> Result<String, Error> {
return Err(Error::NotConfigured(fallback_path));
};

match path.try_exists() {
Ok(true) => {}
Ok(false) => return Err(Error::NotConfigured(path)),
Err(io_error) => return Err(Error::Parse(ParseError::Io(path, io_error))),
}

let content = match fs::read(&path) {
Ok(content) => content,
Err(io_error) => return Err(Error::Parse(ParseError::Io(path, io_error))),
Err(io_error) => {
return Err(if io_error.kind() == ErrorKind::NotFound {
Error::NotConfigured(path)
} else {
Error::Parse(ParseError::Io(path, io_error))
});
}
};

let config: Config = match serde_yaml::from_slice(&content) {
Expand Down

0 comments on commit e5338b7

Please sign in to comment.