Modernized error handling

- Use error-chain instead of writing tons of boilerplate
- Switched try!() macros to '?'
This commit is contained in:
Antoine Gersant 2016-12-03 12:08:55 -08:00
parent 15505f8991
commit ec8a8da81e
14 changed files with 249 additions and 317 deletions

View file

@ -2,28 +2,24 @@ use app_dirs::{AppDataType, data_root};
use std::path::{Path, PathBuf};
use std::fs;
use error::PError;
use errors::*;
pub fn get_config_root() -> Result<PathBuf, PError> {
pub fn get_config_root() -> Result<PathBuf> {
if let Ok(mut root) = data_root(AppDataType::SharedConfig) {
root.push("Polaris");
return match fs::create_dir_all(&root) {
Ok(()) => Ok(root),
Err(_) => Err(PError::CacheDirectoryError),
};
fs::create_dir_all(&root)?;
return Ok(root);
}
Err(PError::ConfigDirectoryError)
bail!("Could not retrieve config directory root");
}
pub fn get_cache_root() -> Result<PathBuf, PError> {
pub fn get_cache_root() -> Result<PathBuf> {
if let Ok(mut root) = data_root(AppDataType::SharedData) {
root.push("Polaris");
return match fs::create_dir_all(&root) {
Ok(()) => Ok(root),
Err(_) => Err(PError::CacheDirectoryError),
};
fs::create_dir_all(&root)?;
return Ok(root);
}
Err(PError::CacheDirectoryError)
bail!("Could not retrieve cache directory root");
}
#[derive(Debug, PartialEq)]