Enhance error printing on config file parsing errors

This commit is contained in:
Matthias Beyer 2016-03-25 15:10:54 +01:00
parent f8c9234a7a
commit c5d5c17208

View file

@ -204,6 +204,8 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
use std::env; use std::env;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::io::Write;
use std::io::stderr;
use xdg_basedir; use xdg_basedir;
use itertools::Itertools; use itertools::Itertools;
@ -238,7 +240,18 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
f.read_to_string(&mut s).ok(); f.read_to_string(&mut s).ok();
s s
}; };
Parser::new(&content[..]).parse() let mut parser = Parser::new(&content[..]);
let res = parser.parse();
if res.is_none() {
write!(stderr(), "Config file parser error:");
for error in parser.errors {
write!(stderr(), "At [{}][{}] <> {}", error.lo, error.hi, error);
write!(stderr(), "in: '{}'", &content[error.lo..error.hi]);
}
None
} else {
res
}
}) })
.filter(|loaded| loaded.is_some()) .filter(|loaded| loaded.is_some())
.nth(0) .nth(0)