summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-08-27 14:11:20 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-08-27 14:14:28 +0200
commit9193d50f96bce099665d2eb716bcaa29a8d9b8ff (patch)
treeb577e3b163ae8ffb27331812b7959b7bf88658c3
parent4475e094577cff07a942343b86aa97ffe55f3270 (diff)
downloadimag-9193d50f96bce099665d2eb716bcaa29a8d9b8ff.zip
imag-9193d50f96bce099665d2eb716bcaa29a8d9b8ff.tar.gz
Fix error while loading
The type inference got our back here into trouble, actually. Because I assumed the type inference would do the thing, I didn't specify the return type for the `::toml::de::from_str` function. Turned out that I assumed it to return a `Option<BTReeMap>` or something like this (which was unintensional, of course). This patch fixes this by specifying the proper return type (plus some more embellishments).
-rw-r--r--libimagrt/src/configuration.rs26
1 files changed, 17 insertions, 9 deletions
diff --git a/libimagrt/src/configuration.rs b/libimagrt/src/configuration.rs
index 1ee76d5..5723276 100644
--- a/libimagrt/src/configuration.rs
+++ b/libimagrt/src/configuration.rs
@@ -36,7 +36,8 @@ generate_error_module!(
);
);
-pub use self::error::{ConfigError, ConfigErrorKind};
+pub use self::error::{ConfigError, ConfigErrorKind, MapErrInto};
+use libimagerror::into::IntoError;
/// Result type of this module. Either `T` or `ConfigError`
pub type Result<T> = RResult<T, ConfigError>;
@@ -255,30 +256,37 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
].iter()
.flatten()
.filter(|path| path.exists() && path.is_file())
- .map(|path| {
+ .filter_map(|path| {
let content = {
- let mut s = String::new();
let f = File::open(path);
if f.is_err() {
+ let _ = write!(stderr(), "Error opening file: {:?}", f);
return None
}
let mut f = f.unwrap();
+
+ let mut s = String::new();
f.read_to_string(&mut s).ok();
s
};
- match ::toml::de::from_str(&content[..]) {
- Ok(res) => res,
+ match ::toml::de::from_str::<::toml::Value>(&content[..]) {
+ Ok(res) => Some(res),
Err(e) => {
- write!(stderr(), "Config file parser error:").ok();
- trace_error(&e);
+ let line_col = e
+ .line_col()
+ .map(|(line, col)| {
+ format!("Line {}, Column {}", line, col)
+ })
+ .unwrap_or_else(|| String::from("Line unknown, Column unknown"));
+
+ let _ = write!(stderr(), "Config file parser error at {}", line_col);
+ trace_error(&ConfigErrorKind::TOMLParserError.into_error_with_cause(Box::new(e)));
None
}
}
})
- .filter(|loaded| loaded.is_some())
.nth(0)
- .map(|inner| Value::Table(inner.unwrap()))
.ok_or(ConfigErrorKind::NoConfigFileFound.into())
}