on master help sign in
produce error when grammar build fails (#6795)
f5d38cePascal Kuthe
helix-loader/src/grammar.rs+22−37
@@ -1,4 +1,4 @@
1−use anyhow::{anyhow, Context, Result};
1+use anyhow::{anyhow, bail, Context, Result};
2use serde::{Deserialize, Serialize};
2use serde::{Deserialize, Serialize};
3use std::fs;
3use std::fs;
4use std::time::SystemTime;
4use std::time::SystemTime;
@@ -98,15 +98,12 @@ pub fn fetch_grammars() -> Result<()> {
98 let mut git_up_to_date = 0;
98 let mut git_up_to_date = 0;
99 let mut non_git = Vec::new();
99 let mut non_git = Vec::new();
100
100
101− for res in results {
101+ for (grammar_id, res) in results {
102 match res {
102 match res {
103 Ok(FetchStatus::GitUpToDate) => git_up_to_date += 1,
103 Ok(FetchStatus::GitUpToDate) => git_up_to_date += 1,
104− Ok(FetchStatus::GitUpdated {
105− grammar_id,
106− revision,
107− }) => git_updated.push((grammar_id, revision)),
104+ Ok(FetchStatus::GitUpdated { revision }) => git_updated.push((grammar_id, revision)),
108− Ok(FetchStatus::NonGit { grammar_id }) => non_git.push(grammar_id),
105+ Ok(FetchStatus::NonGit) => non_git.push(grammar_id),
109− Err(e) => errors.push(e),
106+ Err(e) => errors.push((grammar_id, e)),
110 }
107 }
111 }
108 }
112
109
@@ -138,10 +135,10 @@ pub fn fetch_grammars() -> Result<()> {
138
135
139 if !errors.is_empty() {
136 if !errors.is_empty() {
140 let len = errors.len();
137 let len = errors.len();
141− println!("{} grammars failed to fetch", len);
142− for (i, error) in errors.into_iter().enumerate() {
138+ for (i, (grammar, error)) in errors.into_iter().enumerate() {
143− println!("\tFailure {}/{}: {}", i + 1, len, error);
139+ println!("Failure {}/{len}: {grammar} {error}", i + 1);
144 }
140 }
141+ bail!("{len} grammars failed to fetch");
145 }
142 }
146
143
147 Ok(())
144 Ok(())
@@ -158,11 +155,11 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {
158 let mut already_built = 0;
155 let mut already_built = 0;
159 let mut built = Vec::new();
156 let mut built = Vec::new();
160
157
161− for res in results {
158+ for (grammar_id, res) in results {
162 match res {
159 match res {
163 Ok(BuildStatus::AlreadyBuilt) => already_built += 1,
160 Ok(BuildStatus::AlreadyBuilt) => already_built += 1,
164− Ok(BuildStatus::Built { grammar_id }) => built.push(grammar_id),
161+ Ok(BuildStatus::Built) => built.push(grammar_id),
165− Err(e) => errors.push(e),
162+ Err(e) => errors.push((grammar_id, e)),
166 }
163 }
167 }
164 }
168
165
@@ -179,10 +176,10 @@ pub fn build_grammars(target: Option<String>) -> Result<()> {
179
176
180 if !errors.is_empty() {
177 if !errors.is_empty() {
181 let len = errors.len();
178 let len = errors.len();
182− println!("{} grammars failed to build", len);
183− for (i, error) in errors.into_iter().enumerate() {
179+ for (i, (grammar_id, error)) in errors.into_iter().enumerate() {
184− println!("\tFailure {}/{}: {}", i, len, error);
180+ println!("Failure {}/{len}: {grammar_id} {error}", i + 1);
185 }
181 }
182+ bail!("{len} grammars failed to build");
186 }
183 }
187
184
188 Ok(())
185 Ok(())
@@ -214,7 +211,7 @@ fn get_grammar_configs() -> Result<Vec<GrammarConfiguration>> {
214 Ok(grammars)
211 Ok(grammars)
215}
212}
216
213
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>)>
218where
215where
219 F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,
216 F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,
220 Res: Send + 'static,
217 Res: Send + 'static,
@@ -229,7 +226,7 @@ where
229 pool.execute(move || {
226 pool.execute(move || {
230 // Ignore any SendErrors, if any job in another thread has encountered an
227 // Ignore any SendErrors, if any job in another thread has encountered an
231 // error the Receiver will be closed causing this send to fail.
228 // 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)));
233 });
230 });
234 }
231 }
235
232
@@ -240,13 +237,8 @@ where
240
237
241enum FetchStatus {
238enum FetchStatus {
242 GitUpToDate,
239 GitUpToDate,
243− GitUpdated {
244− grammar_id: String,
245− revision: String,
240+ GitUpdated { revision: String },
246− },
247− NonGit {
241+ NonGit,
248− grammar_id: String,
249− },
250}
242}
251
243
252fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
244fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
@@ -287,17 +279,12 @@ fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
287 )?;
279 )?;
288 git(&grammar_dir, ["checkout", &revision])?;
280 git(&grammar_dir, ["checkout", &revision])?;
289
281
290− Ok(FetchStatus::GitUpdated {
282+ Ok(FetchStatus::GitUpdated { revision })
291− grammar_id: grammar.grammar_id,
292− revision,
293− })
294 } else {
283 } else {
295 Ok(FetchStatus::GitUpToDate)
284 Ok(FetchStatus::GitUpToDate)
296 }
285 }
297 } else {
286 } else {
298− Ok(FetchStatus::NonGit {
287+ Ok(FetchStatus::NonGit)
299− grammar_id: grammar.grammar_id,
300− })
301 }
288 }
302}
289}
303
290
@@ -347,7 +334,7 @@ where
347
334
348enum BuildStatus {
335enum BuildStatus {
349 AlreadyBuilt,
336 AlreadyBuilt,
350− Built { grammar_id: String },
337+ Built,
351}
338}
352
339
353fn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result<BuildStatus> {
340fn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result<BuildStatus> {
@@ -533,9 +520,7 @@ fn build_tree_sitter_library(
533 ));
520 ));
534 }
521 }
535
522
536− Ok(BuildStatus::Built {
523+ Ok(BuildStatus::Built)
537− grammar_id: grammar.grammar_id,
538− })
539}
524}
540
525
541fn needs_recompile(
526fn needs_recompile(