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:🇩🇪: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).
This commit is contained in:
parent
4475e09457
commit
9193d50f96
1 changed files with 17 additions and 9 deletions
|
@ -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`
|
/// Result type of this module. Either `T` or `ConfigError`
|
||||||
pub type Result<T> = RResult<T, ConfigError>;
|
pub type Result<T> = RResult<T, ConfigError>;
|
||||||
|
@ -255,30 +256,37 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
|
||||||
].iter()
|
].iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter(|path| path.exists() && path.is_file())
|
.filter(|path| path.exists() && path.is_file())
|
||||||
.map(|path| {
|
.filter_map(|path| {
|
||||||
let content = {
|
let content = {
|
||||||
let mut s = String::new();
|
|
||||||
let f = File::open(path);
|
let f = File::open(path);
|
||||||
if f.is_err() {
|
if f.is_err() {
|
||||||
|
let _ = write!(stderr(), "Error opening file: {:?}", f);
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
let mut f = f.unwrap();
|
let mut f = f.unwrap();
|
||||||
|
|
||||||
|
let mut s = String::new();
|
||||||
f.read_to_string(&mut s).ok();
|
f.read_to_string(&mut s).ok();
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
||||||
match ::toml::de::from_str(&content[..]) {
|
match ::toml::de::from_str::<::toml::Value>(&content[..]) {
|
||||||
Ok(res) => res,
|
Ok(res) => Some(res),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
write!(stderr(), "Config file parser error:").ok();
|
let line_col = e
|
||||||
trace_error(&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
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(|loaded| loaded.is_some())
|
|
||||||
.nth(0)
|
.nth(0)
|
||||||
.map(|inner| Value::Table(inner.unwrap()))
|
|
||||||
.ok_or(ConfigErrorKind::NoConfigFileFound.into())
|
.ok_or(ConfigErrorKind::NoConfigFileFound.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue