feat(cli): attach helpful context when grammar.json cannot be found

Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
This commit is contained in:
阿良仔 2024-07-06 07:53:47 +08:00 committed by GitHub
parent c185170936
commit 9e0c922b3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;