From 0f93cd002b33377f64a8ac2bf9e183f79538e749 Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Sat, 24 Jun 2017 23:53:08 +0800 Subject: [PATCH] Added error-chain to the config files --- src/config/jsonconfig.rs | 5 +++-- src/config/tomlconfig.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/config/jsonconfig.rs b/src/config/jsonconfig.rs index f41f8763..904787c0 100644 --- a/src/config/jsonconfig.rs +++ b/src/config/jsonconfig.rs @@ -1,5 +1,6 @@ extern crate serde_json; use std::path::PathBuf; +use errors::*; /// The JSON configuration is **deprecated** and will be removed in the near future. /// Please migrate to the TOML configuration. @@ -32,9 +33,9 @@ pub struct JsonConfig { /// assert_eq!(config.dest, Some(PathBuf::from("htmlbook"))); /// ``` impl JsonConfig { - pub fn from_json(input: &str) -> Result { + pub fn from_json(input: &str) -> Result { let config: JsonConfig = serde_json::from_str(input) - .map_err(|e| format!("Could not parse JSON: {}", e))?; + .chain_err(|| format!("Could not parse JSON"))?; return Ok(config); } diff --git a/src/config/tomlconfig.rs b/src/config/tomlconfig.rs index 90cfa4c6..9c6851c5 100644 --- a/src/config/tomlconfig.rs +++ b/src/config/tomlconfig.rs @@ -1,5 +1,6 @@ extern crate toml; use std::path::PathBuf; +use errors::*; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct TomlConfig { @@ -43,9 +44,9 @@ pub struct TomlHtmlConfig { /// assert_eq!(config.output.unwrap().html.unwrap().destination, Some(PathBuf::from("htmlbook"))); /// ``` impl TomlConfig { - pub fn from_toml(input: &str) -> Result { + pub fn from_toml(input: &str) -> Result { let config: TomlConfig = toml::from_str(input) - .map_err(|e| format!("Could not parse TOML: {}", e))?; + .chain_err(|| "Could not parse TOML")?; return Ok(config); }