Added error-chain to the config files

This commit is contained in:
Michael Bryan 2017-06-24 23:53:08 +08:00
parent 6761442241
commit 0f93cd002b
2 changed files with 6 additions and 4 deletions

View File

@ -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<Self, String> {
pub fn from_json(input: &str) -> Result<Self> {
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);
}

View File

@ -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<Self, String> {
pub fn from_toml(input: &str) -> Result<Self> {
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);
}