mirror of
https://github.com/facebook/sapling.git
synced 2024-12-25 05:53:24 +03:00
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:
parent
50a8016efc
commit
6f2adbf2cc
@ -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),
|
||||
|
@ -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),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user