From 9e0c922b3f18e4407e8dd044982e3969682eabe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=89=AF=E4=BB=94?= <32487868+cijiugechu@users.noreply.github.com> Date: Sat, 6 Jul 2024 07:53:47 +0800 Subject: [PATCH] feat(cli): attach helpful context when `grammar.json` cannot be found Co-authored-by: Amaan Qureshi --- cli/loader/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index f05b48af..eb829373 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -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;