From 045fc2b25b89ecd91de8be7aa7c0a90d7ac12039 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Fri, 6 Oct 2023 11:55:33 +0530 Subject: [PATCH] Use assertions for cleaner checks --- src/commands/download.rs | 11 +++-------- src/commands/upload.rs | 4 +++- src/vercel/artifact.rs | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/commands/download.rs b/src/commands/download.rs index da13cbb..43e4387 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -43,18 +43,13 @@ pub async fn download( let output_get_res = output_get_req.get().await?; + assert!(output_get_res.status().is_success(), "Build artifacts could not be downloaded."); + println!("Build artifacts downloaded"); let buf = &output_get_res.bytes().await?.to_vec(); - if !vercel_cache_helper::utils::is_zstd_compressed(&buf) { - return Err(vercel_cache_helper::Error::InvalidInput( - format!( - "Downloaded archive (Size: {}) is not zstd compressed", - &buf.len() - ) - )); - } + assert!(vercel_cache_helper::utils::is_zstd_compressed(&buf), "Downloaded archive (Size: {}) is not zstd compressed.", &buf.len()); output_dir_archive.write_all(buf)?; diff --git a/src/commands/upload.rs b/src/commands/upload.rs index 9c68100..c316078 100644 --- a/src/commands/upload.rs +++ b/src/commands/upload.rs @@ -63,10 +63,12 @@ pub async fn upload( pb.set_message("Uploading artfiacts..."); - output_put_req + let res = output_put_req .buffer(&mut output_archive_buf, output_archive_size) .await?; + assert!(res.status().is_success(), "Could not upload artifacts."); + pb.finish_with_message("Artifacts uploaded successfully."); Ok(()) diff --git a/src/vercel/artifact.rs b/src/vercel/artifact.rs index 0cc6b6f..8858205 100644 --- a/src/vercel/artifact.rs +++ b/src/vercel/artifact.rs @@ -49,7 +49,7 @@ impl RequestHeaders for ArtifactBaseRequest { if method == "PUT" { headers.insert( reqwest::header::CONTENT_TYPE, - reqwest::header::HeaderValue::from_static("application/octet-stream"), + reqwest::header::HeaderValue::from_static("application/zstd"), ); if let Some(content_len) = content_len {