on master help sign in
produce error when grammar build fails (#6795)

* produce error when grammar build fails * print which grammar build failed

commitf5d38cee17e78bf82eb2d0b3070aa9cd52c0a741 authorPascal Kuthe <pascal.kuthe@semimod.de> dateThu 20 Apr 2023, 07:53 (4 years ago) parent83c307a
1 file changed+22−37
helix-loader/src/grammar.rs+22−37
helix-loader/src/grammar.rs+22−37
@@ -1,4 +1,4 @@
1−use anyhow::{anyhow, Context, Result};
1+use anyhow::{anyhow, bail, Context, Result};
22use serde::{Deserialize, Serialize};
33use std::fs;
44use std::time::SystemTime;
@@ -98,15 +98,12 @@ pub fn fetch_grammars() -> Result<()> {
9898 let mut git_up_to_date = 0;
9999 let mut non_git = Vec::new();
100100
101− for res in results {
101+ for (grammar_id, res) in results {
102102 match res {
103103 Ok(FetchStatus::GitUpToDate) => git_up_to_date += 1,
104− Ok(FetchStatus::GitUpdated {
105− grammar_id,
106− revision,
107− }) => git_updated.push((grammar_id, revision)),
108− Ok(FetchStatus::NonGit { grammar_id }) => non_git.push(grammar_id),
109− Err(e) => errors.push(e),
104+ Ok(FetchStatus::GitUpdated { revision }) => git_updated.push((grammar_id, revision)),
105+ Ok(FetchStatus::NonGit) => non_git.push(grammar_id),
106+ Err(e) => errors.push((grammar_id, e)),
110107 }
111108 }
112109
@@ -138,10 +135,10 @@ pub fn fetch_grammars() -> Result<()> {
138135
139136 if !errors.is_empty() {
140137 let len = errors.len();
141− println!("{} grammars failed to fetch", len);
142− for (i, error) in errors.into_iter().enumerate() {
143− println!("\tFailure {}/{}: {}", i + 1, len, error);
138+ for (i, (grammar, error)) in errors.into_iter().enumerate() {
139+ println!("Failure {}/{len}: {grammar} {error}", i + 1);
144140 }
141+ bail!("{len} grammars failed to fetch");
145142 }
146143
147144 Ok(())
@@ -158,11 +155,11 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {
158155 let mut already_built = 0;
159156 let mut built = Vec::new();
160157
161− for res in results {
158+ for (grammar_id, res) in results {
162159 match res {
163160 Ok(BuildStatus::AlreadyBuilt) => already_built += 1,
164− Ok(BuildStatus::Built { grammar_id }) => built.push(grammar_id),
165− Err(e) => errors.push(e),
161+ Ok(BuildStatus::Built) => built.push(grammar_id),
162+ Err(e) => errors.push((grammar_id, e)),
166163 }
167164 }
168165
@@ -179,10 +176,10 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {
179176
180177 if !errors.is_empty() {
181178 let len = errors.len();
182− println!("{} grammars failed to build", len);
183− for (i, error) in errors.into_iter().enumerate() {
184− println!("\tFailure {}/{}: {}", i, len, error);
179+ for (i, (grammar_id, error)) in errors.into_iter().enumerate() {
180+ println!("Failure {}/{len}: {grammar_id} {error}", i + 1);
185181 }
182+ bail!("{len} grammars failed to build");
186183 }
187184
188185 Ok(())
@@ -214,7 +211,7 @@ fn get_grammar_configs() -> Result<Vec<GrammarConfiguration>> {
214211 Ok(grammars)
215212}
216213
217−fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<Result<Res>>
214+fn run_parallel<F, Res>(grammars: Vec<GrammarConfiguration>, job: F) -> Vec<(String, Result<Res>)>
218215where
219216 F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,
220217 Res: Send + 'static,
@@ -229,7 +226,7 @@ where
229226 pool.execute(move || {
230227 // Ignore any SendErrors, if any job in another thread has encountered an
231228 // error the Receiver will be closed causing this send to fail.
232− let _ = tx.send(job(grammar));
229+ let _ = tx.send((grammar.grammar_id.clone(), job(grammar)));
233230 });
234231 }
235232
@@ -240,13 +237,8 @@ where
240237
241238enum FetchStatus {
242239 GitUpToDate,
243− GitUpdated {
244− grammar_id: String,
245− revision: String,
246− },
247− NonGit {
248− grammar_id: String,
249− },
240+ GitUpdated { revision: String },
241+ NonGit,
250242}
251243
252244fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
@@ -287,17 +279,12 @@ fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
287279 )?;
288280 git(&grammar_dir, ["checkout", &revision])?;
289281
290− Ok(FetchStatus::GitUpdated {
291− grammar_id: grammar.grammar_id,
292− revision,
293− })
282+ Ok(FetchStatus::GitUpdated { revision })
294283 } else {
295284 Ok(FetchStatus::GitUpToDate)
296285 }
297286 } else {
298− Ok(FetchStatus::NonGit {
299− grammar_id: grammar.grammar_id,
300− })
287+ Ok(FetchStatus::NonGit)
301288 }
302289}
303290
@@ -347,7 +334,7 @@ where
347334
348335enum BuildStatus {
349336 AlreadyBuilt,
350− Built { grammar_id: String },
337+ Built,
351338}
352339
353340fn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result<BuildStatus> {
@@ -533,9 +520,7 @@ fn build_tree_sitter_library(
533520 ));
534521 }
535522
536− Ok(BuildStatus::Built {
537− grammar_id: grammar.grammar_id,
538− })
523+ Ok(BuildStatus::Built)
539524}
540525
541526fn needs_recompile(