From 1b50c5ce06d2356124991fa48e6881f61f646ca3 Mon Sep 17 00:00:00 2001 From: Naz Date: Fri, 1 Aug 2025 09:47:04 +0100 Subject: =?UTF-8?q?=F0=9F=90=9Bfix:=20exit=20with=20non-zero=20status=20wh?= =?UTF-8?q?en=20error=20occurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/downloader.rs | 2 +- src/error.rs | 4 ++++ src/main.rs | 1 + src/tui.rs | 9 +++++---- 4 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/downloader.rs b/src/downloader.rs index cf78a49..64df06e 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -26,7 +26,7 @@ impl Downloader { let resp = reqwest::get(&url.to_string()).await?; let total_size = resp.content_length().unwrap_or(0); - let bar = make_progress_bar(total_size); + let bar = make_progress_bar(total_size)?; let mut out = tokio::fs::File::create(&path).await?; // Stream download with progress updates diff --git a/src/error.rs b/src/error.rs index 3c51529..39c421d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,9 @@ pub enum Error { #[from] EnvVar(std::env::VarError), + + #[from] + IndicatifTemplate(indicatif::style::TemplateError), } impl core::fmt::Display for Error { @@ -32,6 +35,7 @@ impl core::fmt::Display for Error { Error::Http(e) => write!(fmt, "HTTP error: {e}"), Error::EnvVar(e) => write!(fmt, "Environment variable error: {e}"), Error::InvalidPath => write!(fmt, "Invalid path provided"), + Error::IndicatifTemplate(e) => write!(fmt, "Progress bar template error: {e}"), } } } diff --git a/src/main.rs b/src/main.rs index 1ea31f8..7840fae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,5 +36,6 @@ async fn run() -> Result<()> { async fn main() { if let Err(e) = run().await { eprintln!("Error: {e}"); + std::process::exit(1); } } diff --git a/src/tui.rs b/src/tui.rs index df3504d..2b0a5fd 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1,14 +1,15 @@ use indicatif::{ProgressBar, ProgressStyle}; -pub fn make_progress_bar(size: u64) -> ProgressBar { +use crate::Result; + +pub fn make_progress_bar(size: u64) -> Result { let bar = ProgressBar::new(size); bar.set_style( ProgressStyle::with_template( "{elapsed_precise:.white.dim} {wide_bar:.cyan} {bytes}/{total_bytes} ({bytes_per_sec}, {eta})", - ) - .unwrap() + )? .progress_chars("█▉▊▋▌▍▎▏ "), ); - bar + Ok(bar) } -- cgit v1.2.3