From 0c3fa34c94609a0c62ed75b252d7c21171e84011 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Thu, 23 May 2024 15:08:51 +0530 Subject: [PATCH] chore(uploader): return summary when upload fails due to max repayments --- sn_client/src/error.rs | 12 ++++++++++-- sn_client/src/uploader/tests/mod.rs | 2 +- sn_client/src/uploader/upload.rs | 25 +++++++++++++------------ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/sn_client/src/error.rs b/sn_client/src/error.rs index 12926da328..20886f1370 100644 --- a/sn_client/src/error.rs +++ b/sn_client/src/error.rs @@ -8,6 +8,8 @@ pub(crate) type Result = std::result::Result; +use crate::UploadSummary; + use super::ClientEvent; use sn_protocol::NetworkAddress; use sn_registers::{Entry, EntryHash}; @@ -140,8 +142,14 @@ pub enum Error { #[error("Too many sequential payment errors reported during upload")] SequentialUploadPaymentError, - #[error("The maximum specified repayments has been reached for {0:?}")] - MaximumRepaymentsReached(Vec), + #[error("The maximum specified repayments has been reached for a single item: {0:?}")] + MaximumRepaymentsReached(XorName), + + #[error("The upload failed with maximum repayments reached for multiple items: {items:?} Summary: {summary:?}")] + UploadFailedWithMaximumRepaymentsReached { + items: Vec, + summary: UploadSummary, + }, #[error("Error occurred when access wallet file")] FailedToAccessWallet, diff --git a/sn_client/src/uploader/tests/mod.rs b/sn_client/src/uploader/tests/mod.rs index b2e1728918..7f28f3e6d0 100644 --- a/sn_client/src/uploader/tests/mod.rs +++ b/sn_client/src/uploader/tests/mod.rs @@ -448,7 +448,7 @@ async fn maximum_repayment_error_should_be_triggered_during_get_store_cost() -> assert_matches!( upload_handle.await?, - Err(ClientError::MaximumRepaymentsReached(_)) + Err(ClientError::UploadFailedWithMaximumRepaymentsReached { .. }) ); let events = events_handle.await?; diff --git a/sn_client/src/uploader/upload.rs b/sn_client/src/uploader/upload.rs index 102a2f0db6..d04acd3c82 100644 --- a/sn_client/src/uploader/upload.rs +++ b/sn_client/src/uploader/upload.rs @@ -122,17 +122,6 @@ pub(super) async fn start_upload( .balance(); #[cfg(test)] trace!("UPLOADER STATE: finished uploading all items {uploader:?}"); - - if !uploader.max_repayments_reached.is_empty() { - error!( - "The maximum repayments were reached for these addresses: {:?}", - uploader.max_repayments_reached - ); - return Err(ClientError::MaximumRepaymentsReached( - uploader.max_repayments_reached.into_iter().collect(), - )); - } - let summary = UploadSummary { storage_cost: uploader.upload_storage_cost, royalty_fees: uploader.upload_royalty_fees, @@ -142,6 +131,18 @@ pub(super) async fn start_upload( skipped_count: uploader.skipped_count, uploaded_registers: uploader.uploaded_registers, }; + + if !uploader.max_repayments_reached.is_empty() { + error!( + "The maximum repayments were reached for these addresses: {:?}", + uploader.max_repayments_reached + ); + return Err(ClientError::UploadFailedWithMaximumRepaymentsReached { + items: uploader.max_repayments_reached.into_iter().collect(), + summary, + }); + } + return Ok(summary); } @@ -942,7 +943,7 @@ impl InnerUploader { max_repayments_for_failed_data, ) { // error is used by the caller. - return Err(ClientError::MaximumRepaymentsReached(vec![xorname])); + return Err(ClientError::MaximumRepaymentsReached(xorname)); } debug!("Filtering out payments from {filter_list:?} during get_store_cost for {xorname:?}");