feat(cli): attach helpful context when grammar.json cannot be found
Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
This commit is contained in:
parent
c185170936
commit
9e0c922b3f
1 changed files with 12 additions and 3 deletions
|
|
@ -415,10 +415,19 @@ impl Loader {
|
|||
struct GrammarJSON {
|
||||
name: String,
|
||||
}
|
||||
let mut grammar_file =
|
||||
fs::File::open(grammar_path).with_context(|| "Failed to read grammar.json")?;
|
||||
let mut grammar_file = fs::File::open(&grammar_path).with_context(|| {
|
||||
format!(
|
||||
"Failed to read grammar.json file at the following path:\n{:?}",
|
||||
&grammar_path
|
||||
)
|
||||
})?;
|
||||
let grammar_json: GrammarJSON = serde_json::from_reader(BufReader::new(&mut grammar_file))
|
||||
.with_context(|| "Failed to parse grammar.json")?;
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to parse grammar.json file at the following path:\n{:?}",
|
||||
&grammar_path
|
||||
)
|
||||
})?;
|
||||
|
||||
config.name = grammar_json.name;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue