edenapi: include field names in malformed config errors

Summary: Include the name of bad config fields in the error message so the user can more easily fix the problem.

Reviewed By: quark-zju

Differential Revision: D22591871

fbshipit-source-id: e23e2c71e49e0458e7ea5c13e7feac3a990ead0c
This commit is contained in:
Arun Kulshreshtha 2020-07-16 21:24:58 -07:00 committed by Facebook GitHub Bot
parent 50a8016efc
commit 6f2adbf2cc
2 changed files with 6 additions and 6 deletions

View File

@ -41,7 +41,7 @@ impl Builder {
pub fn from_config(config: &ConfigSet) -> Result<Self, EdenApiError> {
let server_url = config
.get_opt::<String>("edenapi", "url")
.map_err(ConfigError::Malformed)?
.map_err(|e| ConfigError::Malformed("edenapi.url".into(), e))?
.ok_or(ConfigError::MissingUrl)?
.parse::<Url>()
.map_err(ConfigError::InvalidUrl)?;
@ -53,15 +53,15 @@ impl Builder {
let max_files = config
.get_opt("edenapi", "maxfiles")
.map_err(ConfigError::Malformed)?;
.map_err(|e| ConfigError::Malformed("edenapi.maxfiles".into(), e))?;
let max_trees = config
.get_opt("edenapi", "maxtrees")
.map_err(ConfigError::Malformed)?;
.map_err(|e| ConfigError::Malformed("edenapi.maxtrees".into(), e))?;
let max_history = config
.get_opt("edenapi", "maxhistory")
.map_err(ConfigError::Malformed)?;
.map_err(|e| ConfigError::Malformed("edenapi.maxhistory".into(), e))?;
Ok(Self {
server_url: Some(server_url),

View File

@ -33,6 +33,6 @@ pub enum ConfigError {
MissingUrl,
#[error("Invalid server URL: {0}")]
InvalidUrl(#[source] url::ParseError),
#[error("Config value is malformed: {0}")]
Malformed(#[source] anyhow::Error),
#[error("Config field '{0}' is malformed")]
Malformed(String, #[source] anyhow::Error),
}