diff --git a/manifest/src/lib.rs b/manifest/src/lib.rs index 014c68be9..3c4c4ce4d 100644 --- a/manifest/src/lib.rs +++ b/manifest/src/lib.rs @@ -42,7 +42,8 @@ pub fn get_manifests>(path: P) -> Result> { } fn parse_cargo_manifest(path: &Path) -> Result { - let m = cargo_toml::Manifest::from_path(path)?; + let m = cargo_toml::Manifest::from_path(path) + .with_context(|| format!("Failed to parse Cargo.toml at '{}'", path.display()))?; let package = m.package.context("Not a package (only a workspace)")?; let description = package.description().map(|v| v.into()); @@ -57,7 +58,8 @@ fn parse_cargo_manifest(path: &Path) -> Result { } fn parse_npm_manifest(path: &Path) -> Result { - let package = npm_package_json::Package::from_path(path)?; + let package = npm_package_json::Package::from_path(path) + .with_context(|| format!("Failed to parse package.json at '{}'", path.display()))?; Ok(Manifest { manifest_type: ManifestType::Npm, number_of_dependencies: package.dependencies.len(), diff --git a/src/info/git/mod.rs b/src/info/git/mod.rs index 8c2065513..210240052 100644 --- a/src/info/git/mod.rs +++ b/src/info/git/mod.rs @@ -222,7 +222,7 @@ fn should_break( return false; } - max_churn_pool_size_opt.map_or(true, |max_churn_pool_size| { + max_churn_pool_size_opt.is_none_or(|max_churn_pool_size| { number_of_diffs_computed >= max_churn_pool_size.min(total_number_of_commits) }) } diff --git a/src/info/langs/mod.rs b/src/info/langs/mod.rs index f723d9921..f4b5a2e3f 100644 --- a/src/info/langs/mod.rs +++ b/src/info/langs/mod.rs @@ -21,8 +21,14 @@ pub fn get_loc_by_language_sorted( ) -> Result> { let locs = get_locs(dir, globs_to_exclude, language_types, include_hidden); - let loc_by_language = - get_loc_by_language(&locs).context("Could not find any source code in this repository")?; + let loc_by_language = get_loc_by_language(&locs).with_context(|| { + format!( + "No source code found in the repository at '{}'. \ + Note: Some language types (prose, data) are excluded by default. \ + Consider using the '--type' option to include them.", + dir.display() + ) + })?; let loc_by_language_sorted = sort_by_loc(loc_by_language); diff --git a/src/info/license.rs b/src/info/license.rs index 20b74d663..2713fa85c 100644 --- a/src/info/license.rs +++ b/src/info/license.rs @@ -22,8 +22,8 @@ impl Detector { pub fn new() -> Result { match Store::from_cache(CACHE_DATA) { Ok(store) => Ok(Self { store }), - Err(_) => { - bail!("Could not initialize the license detector") + Err(e) => { + bail!("Could not initialize the license detector: {}", e) } } } diff --git a/src/info/mod.rs b/src/info/mod.rs index a5c2a54ec..933f0857d 100644 --- a/src/info/mod.rs +++ b/src/info/mod.rs @@ -147,14 +147,16 @@ pub fn build_info(cli_options: &CliOptions) -> Result { &repo, cli_options.info.hide_token, cli_options.info.http_url, - )?; + ) + .context("Failed to determine repository URL")?; let git_metrics = traverse_commit_graph( &repo, cli_options.info.no_bots.clone(), cli_options.info.churn_pool_size, cli_options.info.no_merges, - )?; + ) + .context("Failed to traverse Git commit history")?; let true_color = match cli_options.ascii.true_color { When::Always => true, When::Never => false, diff --git a/src/ui/printer.rs b/src/ui/printer.rs index 6661dbeb8..a5f07b5a0 100644 --- a/src/ui/printer.rs +++ b/src/ui/printer.rs @@ -31,10 +31,13 @@ pub struct Printer { impl Printer { pub fn new(writer: W, info: Info, cli_options: CliOptions) -> Result { - let image = match cli_options.image.image { - Some(p) => Some(image::open(p).context("Could not load the specified image")?), - None => None, - }; + let image = + match cli_options.image.image { + Some(p) => Some(image::open(&p).with_context(|| { + format!("Could not load the image file at '{}'", p.display()) + })?), + None => None, + }; let image_backend = if image.is_some() { cli_options @@ -83,7 +86,7 @@ impl Printer { let image_backend = self .image_backend .as_ref() - .context("Could not detect a supported image backend")?; + .context("No supported image backend detected on your system")?; buf.push_str( &image_backend @@ -92,7 +95,7 @@ impl Printer { custom_image, self.color_resolution, ) - .context("Error while drawing image")?, + .context("Failed to render the image in the terminal")?, ); } else { let mut logo_lines = if let Some(custom_ascii) = &self.ascii_input {