From 29c3640e5fea0f423357c28e3c221fcaca004ee8 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 31 Jul 2025 15:46:40 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20use=20the=20custom=20Result=20type=20i?= =?UTF-8?q?nstead=20of=20the=20standard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/downloader.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/downloader.rs') diff --git a/src/downloader.rs b/src/downloader.rs index 2196e25..be35bd8 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::{appimages_dir, make_progress_bar}; +use crate::{Result, appimages_dir, make_progress_bar}; #[derive(Debug, Default)] pub struct Downloader {} @@ -20,11 +20,7 @@ impl Downloader { appimages_dir().join(filename) } - pub async fn download_with_progress( - &self, - url: &str, - path: &PathBuf, - ) -> Result<(), Box> { + 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?; -- cgit v1.2.3 From 180fe06facf1f8b4796df69a42596643990b9d32 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 31 Jul 2025 15:59:56 +0100 Subject: =?UTF-8?q?=E2=9C=A8feat:=20remove=20expect=20from=20path=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/downloader.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/downloader.rs') diff --git a/src/downloader.rs b/src/downloader.rs index be35bd8..cf78a49 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -11,17 +11,17 @@ impl Downloader { pub fn new() -> Self { Self {} } - pub fn prepare_path(&self, url: &str, executable: &str) -> PathBuf { + pub fn prepare_path(&self, url: &str, executable: &str) -> Result { // Try to extract filename from URL or use default let filename = match url.split('/').next_back() { Some(name) => name.to_string(), None => format!("{executable}.AppImage"), }; - appimages_dir().join(filename) + Ok(appimages_dir()?.join(filename)) } pub async fn download_with_progress(&self, url: &str, path: &PathBuf) -> Result<()> { - fs::create_dir_all(&appimages_dir()).await?; + fs::create_dir_all(&appimages_dir()?).await?; let resp = reqwest::get(&url.to_string()).await?; let total_size = resp.content_length().unwrap_or(0); -- cgit v1.2.3 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/downloader.rs') 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 -- cgit v1.2.3 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