From dc0ee6ce99a0480b7a6c228492936b16ceaf60cd Mon Sep 17 00:00:00 2001 From: Naz Date: Sun, 3 Aug 2025 10:06:33 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20add=20a=20more=20spesific=20error=20fo?= =?UTF-8?q?r=20the=20download=20process?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/downloader.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/downloader.rs') diff --git a/src/downloader.rs b/src/downloader.rs index 64df06e..0141424 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -2,7 +2,7 @@ use futures_util::StreamExt; use std::path::PathBuf; use tokio::{fs, io::AsyncWriteExt}; -use crate::{Result, appimages_dir, make_progress_bar}; +use crate::{Error, Result, appimages_dir, make_progress_bar}; #[derive(Debug, Default)] pub struct Downloader {} @@ -23,7 +23,12 @@ impl Downloader { pub async fn download_with_progress(&self, url: &str, path: &PathBuf) -> Result<()> { fs::create_dir_all(&appimages_dir()?).await?; - let resp = reqwest::get(&url.to_string()).await?; + let resp = reqwest::get(&url.to_string()) + .await + .map_err(|source| Error::Download { + url: url.to_string(), + source, + })?; let total_size = resp.content_length().unwrap_or(0); let bar = make_progress_bar(total_size)?; @@ -32,7 +37,10 @@ impl Downloader { // Stream download with progress updates let mut stream = resp.bytes_stream(); while let Some(chunk) = stream.next().await { - let chunk = chunk?; + let chunk = chunk.map_err(|source| Error::Download { + url: url.to_string(), + source, + })?; let len = chunk.len() as u64; out.write_all(&chunk).await?; bar.inc(len); -- cgit v1.2.3