From 288cf0b196b0ef24e66a6720c29084fc8e43ebf4 Mon Sep 17 00:00:00 2001 From: FallBackITA27 Date: Thu, 11 Jul 2024 13:23:35 +0200 Subject: [PATCH 1/2] more detailed errors --- src/http_async.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/http_async.rs b/src/http_async.rs index 1ca8032..e55afae 100644 --- a/src/http_async.rs +++ b/src/http_async.rs @@ -49,9 +49,13 @@ pub async fn download_file_progress( let mut stream = res.bytes_stream(); while let Some(item) = stream.next().await { - let chunk = item.or(Err("Error while downloading file"))?; - file.write_all(&chunk) - .or(Err("Error while writing to file"))?; + let chunk = match item { + Ok(v) => v, + Err(e) => return Err(format!("Error while downloading file: {e}")) + }; + if let Err(e) = file.write_all(&chunk) { + Err(format!("Error while writing to file: {e}"))? + } let new = min(downloaded + (chunk.len() as u64), total_size); downloaded = new; pb.set_position(new); From a81c4eedfc3f0508c448357742ae7332f10f5fa0 Mon Sep 17 00:00:00 2001 From: FallBackITA27 Date: Thu, 11 Jul 2024 13:26:39 +0200 Subject: [PATCH 2/2] cargo fmt --- src/http_async.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http_async.rs b/src/http_async.rs index e55afae..70971d2 100644 --- a/src/http_async.rs +++ b/src/http_async.rs @@ -51,7 +51,7 @@ pub async fn download_file_progress( while let Some(item) = stream.next().await { let chunk = match item { Ok(v) => v, - Err(e) => return Err(format!("Error while downloading file: {e}")) + Err(e) => return Err(format!("Error while downloading file: {e}")), }; if let Err(e) = file.write_all(&chunk) { Err(format!("Error while writing to file: {e}"))?