Skip to content

Commit 82da923

Browse files
authored
Fix OOB error
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.
1 parent 9e5a263 commit 82da923

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/info/langs/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Result};
1+
use anyhow::{anyhow, Context, Result};
22
use gengo::{Builder, Git};
33

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

1010
pub mod language;
1111

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

1620
/// Returns a vector of tuples containing all the languages detected inside the repository.

src/info/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn build_info(cli_options: &CliOptions) -> Result<Info> {
158158
When::Never => false,
159159
When::Auto => is_truecolor_terminal(),
160160
};
161-
let dominant_language = langs::get_main_language(&size_by_language);
161+
let dominant_language = langs::get_main_language(&size_by_language)?;
162162
let ascii_colors = get_ascii_colors(
163163
&cli_options.ascii.ascii_language,
164164
&dominant_language,

0 commit comments

Comments
 (0)