Fix: Do not ignore errors in config anymore

The function already returns `Result<_>`, the only thing that had to be
done was refactoring the code for actually returning an error in that
case.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-11-06 20:01:53 +01:00
parent feea57679d
commit 44495d6efe

View file

@ -388,15 +388,17 @@ impl<'a> Runtime<'a> {
self.cli() self.cli()
.value_of("editor") .value_of("editor")
.map(String::from) .map(String::from)
.or_else(|| { .ok_or_else(|| {
self.config() self.config()
.and_then(|v| match v.read("rt.editor") { .ok_or_else(|| Error::from(err_msg("No Configuration!")))
Ok(Some(&Value::String(ref s))) => Some(s.clone()), .and_then(|v| match v.read("rt.editor")? {
_ => None, // FIXME silently ignore errors in config is bad Some(&Value::String(ref s)) => Ok(Some(s.clone())),
Some(_) => Err(Error::from(err_msg("Type error at 'rt.editor', expected 'String'"))),
None => Ok(None),
}) })
}) })
.or(env::var("EDITOR").ok()) .or(env::var("EDITOR"))
.ok_or_else(|| Error::from(EM::IO)) .map_err(|_| Error::from(EM::IO))
.map_dbg(|s| format!("Editing with '{}'", s)) .map_dbg(|s| format!("Editing with '{}'", s))
.and_then(|s| { .and_then(|s| {
let mut split = s.split_whitespace(); let mut split = s.split_whitespace();