From 06b8889d279fc341fca83a8dc88107f6df431fdb Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Wed, 25 Feb 2026 12:28:28 +0100 Subject: [PATCH] fix(cli): avoid panics in progress styling --- crates/karapace-cli/src/commands/mod.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/karapace-cli/src/commands/mod.rs b/crates/karapace-cli/src/commands/mod.rs index 5eb5873..f98ea47 100644 --- a/crates/karapace-cli/src/commands/mod.rs +++ b/crates/karapace-cli/src/commands/mod.rs @@ -40,23 +40,26 @@ pub fn json_pretty(value: &impl serde::Serialize) -> Result { pub fn spinner(msg: &str) -> ProgressBar { let pb = ProgressBar::new_spinner(); - pb.set_style( - ProgressStyle::with_template("{spinner:.cyan} {msg}") - .expect("valid template") - .tick_strings(&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]), - ); + let style = ProgressStyle::with_template("{spinner:.cyan} {msg}") + .unwrap_or_else(|_| ProgressStyle::default_spinner()) + .tick_strings(&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]); + pb.set_style(style); pb.set_message(msg.to_owned()); pb.enable_steady_tick(Duration::from_millis(80)); pb } pub fn spin_ok(pb: &ProgressBar, msg: &str) { - pb.set_style(ProgressStyle::with_template("{msg}").expect("valid template")); + if let Ok(style) = ProgressStyle::with_template("{msg}") { + pb.set_style(style); + } pb.finish_with_message(format!("✓ {msg}")); } pub fn spin_fail(pb: &ProgressBar, msg: &str) { - pb.set_style(ProgressStyle::with_template("{msg}").expect("valid template")); + if let Ok(style) = ProgressStyle::with_template("{msg}") { + pb.set_style(style); + } pb.finish_with_message(format!("✗ {msg}")); }