summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaz <ndpm13@ch-naseem.com>2025-08-01 09:47:04 +0100
committerNaz <ndpm13@ch-naseem.com>2025-08-01 09:47:04 +0100
commit1b50c5ce06d2356124991fa48e6881f61f646ca3 (patch)
treee291498bc9b03d16ba16ecb882f7724d57853eb3
parent180fe06facf1f8b4796df69a42596643990b9d32 (diff)
🐛fix: exit with non-zero status when error occurs
-rw-r--r--src/downloader.rs2
-rw-r--r--src/error.rs4
-rw-r--r--src/main.rs1
-rw-r--r--src/tui.rs9
4 files changed, 11 insertions, 5 deletions
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<ProgressBar> {
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)
}