|
|
@ -78,13 +78,23 @@ fn get_default_config() -> Config { |
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ConfigError;
|
|
|
|
pub struct ConfigError {
|
|
|
|
description: String |
|
|
|
}
|
|
|
|
|
|
|
|
impl ConfigError {
|
|
|
|
fn new(description: &str) -> ConfigError {
|
|
|
|
ConfigError {
|
|
|
|
description: String::from(description)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error for ConfigError {}
|
|
|
|
|
|
|
|
impl fmt::Display for ConfigError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "Configuration Error")
|
|
|
|
write!(f, "Configuration Error: {}", self.description)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@ -92,7 +102,7 @@ fn read_config(yaml_str: &str) -> Result<Config, ConfigError> { |
|
|
|
match serde_yaml::from_str(yaml_str) {
|
|
|
|
Ok(v) => Result::Ok(v),
|
|
|
|
// File wasn't valid Config/YAML
|
|
|
|
Err(_e) => Result::Err(ConfigError{})
|
|
|
|
Err(_e) => Result::Err(ConfigError::new("Configuration file was invalid"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@ -106,14 +116,14 @@ pub fn load_config(path: &str) -> Result<Config, ConfigError> { |
|
|
|
read_config(&contents)
|
|
|
|
} else {
|
|
|
|
// File was empty
|
|
|
|
Result::Err(ConfigError{})
|
|
|
|
Result::Err(ConfigError::new("Configuration file was empty"))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// File couldn't be read
|
|
|
|
Err(_e) => Result::Err(ConfigError{})
|
|
|
|
Err(_e) => Result::Err(ConfigError::new("Configuration file could not be read"))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// File Doesn't exist
|
|
|
|
Err(_e) => Result::Err(ConfigError{})
|
|
|
|
Err(_e) => Result::Err(ConfigError::new(&format!("Configuration file doesn't exist \"{}\"", path)))
|
|
|
|
}
|
|
|
|
}
|