From f5d38cee17e78bf82eb2d0b3070aa9cd52c0a741 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Thu, 20 Apr 2023 07:53:16 +0200 Subject: [PATCH] produce error when grammar build fails (#6795) * produce error when grammar build fails * print which grammar build failed --- helix-loader/src/grammar.rs | 59 ++++++++++++++----------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/helix-loader/src/grammar.rs b/helix-loader/src/grammar.rs index 3697ec7e1..a5dcc4c8a 100644 --- a/helix-loader/src/grammar.rs +++ b/helix-loader/src/grammar.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use serde::{Deserialize, Serialize}; use std::fs; use std::time::SystemTime; @@ -98,15 +98,12 @@ pub fn fetch_grammars() -> Result<()> { let mut git_up_to_date = 0; let mut non_git = Vec::new(); - for res in results { + for (grammar_id, res) in results { match res { Ok(FetchStatus::GitUpToDate) => git_up_to_date += 1, - Ok(FetchStatus::GitUpdated { - grammar_id, - revision, - }) => git_updated.push((grammar_id, revision)), - Ok(FetchStatus::NonGit { grammar_id }) => non_git.push(grammar_id), - Err(e) => errors.push(e), + Ok(FetchStatus::GitUpdated { revision }) => git_updated.push((grammar_id, revision)), + Ok(FetchStatus::NonGit) => non_git.push(grammar_id), + Err(e) => errors.push((grammar_id, e)), } } @@ -138,10 +135,10 @@ pub fn fetch_grammars() -> Result<()> { if !errors.is_empty() { let len = errors.len(); - println!("{} grammars failed to fetch", len); - for (i, error) in errors.into_iter().enumerate() { - println!("\tFailure {}/{}: {}", i + 1, len, error); + for (i, (grammar, error)) in errors.into_iter().enumerate() { + println!("Failure {}/{len}: {grammar} {error}", i + 1); } + bail!("{len} grammars failed to fetch"); } Ok(()) @@ -158,11 +155,11 @@ pub fn build_grammars(target: Option) -> Result<()> { let mut already_built = 0; let mut built = Vec::new(); - for res in results { + for (grammar_id, res) in results { match res { Ok(BuildStatus::AlreadyBuilt) => already_built += 1, - Ok(BuildStatus::Built { grammar_id }) => built.push(grammar_id), - Err(e) => errors.push(e), + Ok(BuildStatus::Built) => built.push(grammar_id), + Err(e) => errors.push((grammar_id, e)), } } @@ -179,10 +176,10 @@ pub fn build_grammars(target: Option) -> Result<()> { if !errors.is_empty() { let len = errors.len(); - println!("{} grammars failed to build", len); - for (i, error) in errors.into_iter().enumerate() { - println!("\tFailure {}/{}: {}", i, len, error); + for (i, (grammar_id, error)) in errors.into_iter().enumerate() { + println!("Failure {}/{len}: {grammar_id} {error}", i + 1); } + bail!("{len} grammars failed to build"); } Ok(()) @@ -214,7 +211,7 @@ fn get_grammar_configs() -> Result> { Ok(grammars) } -fn run_parallel(grammars: Vec, job: F) -> Vec> +fn run_parallel(grammars: Vec, job: F) -> Vec<(String, Result)> where F: Fn(GrammarConfiguration) -> Result + Send + 'static + Clone, Res: Send + 'static, @@ -229,7 +226,7 @@ fn run_parallel(grammars: Vec, job: F) -> Vec(grammars: Vec, job: F) -> Vec Result { @@ -287,17 +279,12 @@ fn fetch_grammar(grammar: GrammarConfiguration) -> Result { )?; git(&grammar_dir, ["checkout", &revision])?; - Ok(FetchStatus::GitUpdated { - grammar_id: grammar.grammar_id, - revision, - }) + Ok(FetchStatus::GitUpdated { revision }) } else { Ok(FetchStatus::GitUpToDate) } } else { - Ok(FetchStatus::NonGit { - grammar_id: grammar.grammar_id, - }) + Ok(FetchStatus::NonGit) } } @@ -347,7 +334,7 @@ fn git(repository_dir: &Path, args: I) -> Result enum BuildStatus { AlreadyBuilt, - Built { grammar_id: String }, + Built, } fn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result { @@ -533,9 +520,7 @@ fn build_tree_sitter_library( )); } - Ok(BuildStatus::Built { - grammar_id: grammar.grammar_id, - }) + Ok(BuildStatus::Built) } fn needs_recompile(