Skip to content

Commit

Permalink
Fix OOB error
Browse files Browse the repository at this point in the history
This was introduced by the removal of `get_loc_by_language`, which had
a check to return `None` if the total LoC was `0`. This will now check
if the list of languages is empty.
  • Loading branch information
spenserblack committed May 3, 2024
1 parent 9e5a263 commit 82da923
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/info/langs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};
use gengo::{Builder, Git};

use globset::{Glob, GlobSetBuilder};
Expand All @@ -9,8 +9,12 @@ use std::path::Path;

pub mod language;

pub fn get_main_language(size_by_language: &[(Language, usize)]) -> Language {
size_by_language[0].0
pub fn get_main_language(size_by_language: &[(Language, usize)]) -> Result<Language> {
// TODO This function only works with an already-sorted slice, so it doesn't have much utility
let (language, _) = size_by_language
.get(0)
.context("Could not find any source code in this repository")?;
Ok(*language)
}

/// Returns a vector of tuples containing all the languages detected inside the repository.
Expand Down
2 changes: 1 addition & 1 deletion src/info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn build_info(cli_options: &CliOptions) -> Result<Info> {
When::Never => false,
When::Auto => is_truecolor_terminal(),
};
let dominant_language = langs::get_main_language(&size_by_language);
let dominant_language = langs::get_main_language(&size_by_language)?;
let ascii_colors = get_ascii_colors(
&cli_options.ascii.ascii_language,
&dominant_language,
Expand Down

0 comments on commit 82da923

Please sign in to comment.