From 1f7d3a34e76c9ce01a7b0374b9577f9b20314774 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Tue, 14 Feb 2023 09:45:55 +0000 Subject: [PATCH] Check before unwrapping in stats (#717) Should fix the error @pdecat found! --- src/command/client/stats.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/command/client/stats.rs b/src/command/client/stats.rs index b663423..45bc357 100644 --- a/src/command/client/stats.rs +++ b/src/command/client/stats.rs @@ -26,9 +26,13 @@ pub struct Cmd { fn compute_stats(history: &[History], count: usize) -> Result<()> { let mut commands = HashMap::<&str, usize>::new(); for i in history { - *commands - .entry(i.command.split_ascii_whitespace().next().unwrap()) - .or_default() += 1; + let command = i.command.split_ascii_whitespace().next(); + + if command.is_none() { + continue; + } + + *commands.entry(command.unwrap()).or_default() += 1; } let unique = commands.len(); let mut top = commands.into_iter().collect::>();