Enhance error printing on config file parsing errors
This commit is contained in:
parent
f8c9234a7a
commit
c5d5c17208
1 changed files with 14 additions and 1 deletions
|
@ -204,6 +204,8 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
|
|||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::io::stderr;
|
||||
|
||||
use xdg_basedir;
|
||||
use itertools::Itertools;
|
||||
|
@ -238,7 +240,18 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
|
|||
f.read_to_string(&mut s).ok();
|
||||
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())
|
||||
.nth(0)
|
||||
|
|
Loading…
Reference in a new issue