Skip to content

Commit

Permalink
refactor: rename recoverable to retryable
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Aug 16, 2024
1 parent b773552 commit b609064
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tap_core/src/manager/tap_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ where
let receipt = receipt
.finalize_receipt_checks(&self.checks)
.await
.map_err(|e| Error::ReceiptError(ReceiptError::RecoverableCheckError(e)))?;
.map_err(|e| Error::ReceiptError(ReceiptError::RetryableCheck(e)))?;

match receipt {
Ok(checked) => awaiting_reserve_receipts.push(checked),
Expand Down
2 changes: 1 addition & 1 deletion tap_core/src/receipt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub type CheckResult = Result<(), CheckError>;
#[derive(thiserror::Error, Debug)]
pub enum CheckError {
#[error(transparent)]
Recoverable(anyhow::Error),
Retryable(anyhow::Error),
#[error(transparent)]
Failure(anyhow::Error),
}
Expand Down
4 changes: 2 additions & 2 deletions tap_core/src/receipt/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum ReceiptError {
#[error("Attempt to collect escrow failed")]
SubtractEscrowFailed,
#[error("Issue encountered while performing check: {0}")]
CheckFailedToComplete(String),
CheckFailure(String),
#[error("Issue encountered while performing check: {0}")]
RecoverableCheckError(String),
RetryableCheck(String),
}
6 changes: 3 additions & 3 deletions tap_core/src/receipt/received_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ impl ReceiptWithState<Checking> {
for check in checks {
// return early on an error
check.check(self).await.map_err(|e| match e {
CheckError::Recoverable(e) => ReceiptError::RecoverableCheckError(e.to_string()),
CheckError::Failure(e) => ReceiptError::CheckFailedToComplete(e.to_string()),
CheckError::Retryable(e) => ReceiptError::RetryableCheck(e.to_string()),
CheckError::Failure(e) => ReceiptError::CheckFailure(e.to_string()),
})?;
}
Ok(())
Expand All @@ -111,7 +111,7 @@ impl ReceiptWithState<Checking> {
checks: &[ReceiptCheck],
) -> Result<ResultReceipt<AwaitingReserve>, String> {
let all_checks_passed = self.perform_checks(checks).await;
if let Err(ReceiptError::RecoverableCheckError(e)) = all_checks_passed {
if let Err(ReceiptError::RetryableCheck(e)) = all_checks_passed {
Err(e.to_string())
} else if let Err(e) = all_checks_passed {
Ok(Err(self.perform_state_error(e)))
Expand Down
12 changes: 6 additions & 6 deletions tap_core/tests/manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,21 +535,21 @@ async fn manager_create_rav_and_ignore_invalid_receipts(

#[rstest]
#[tokio::test]
async fn test_recoverable_checks(
async fn test_retryable_checks(
allocation_ids: Vec<Address>,
domain_separator: Eip712Domain,
context: ContextFixture,
) {
struct RecoverableCheck(Arc<AtomicBool>);
struct RetryableCheck(Arc<AtomicBool>);

#[async_trait::async_trait]
impl Check for RecoverableCheck {
impl Check for RetryableCheck {
async fn check(&self, receipt: &ReceiptWithState<Checking>) -> Result<(), CheckError> {
// we want to fail only if nonce is 5 and if is create rav step
if self.0.load(std::sync::atomic::Ordering::SeqCst)
&& receipt.signed_receipt().message.nonce == 5
{
Err(CheckError::Recoverable(anyhow!("Recoverable error")))
Err(CheckError::Retryable(anyhow!("Recoverable error")))
} else {
Ok(())
}
Expand All @@ -567,7 +567,7 @@ async fn test_recoverable_checks(
let is_create_rav = Arc::new(AtomicBool::new(false));

let mut checks: Vec<Arc<dyn Check + Send + Sync>> = checks.iter().cloned().collect();
checks.push(Arc::new(RecoverableCheck(is_create_rav.clone())));
checks.push(Arc::new(RetryableCheck(is_create_rav.clone())));

let manager = Manager::new(
domain_separator.clone(),
Expand Down Expand Up @@ -602,7 +602,7 @@ async fn test_recoverable_checks(

assert_eq!(
rav_request.expect_err("Didn't fail").to_string(),
tap_core::Error::ReceiptError(tap_core::receipt::ReceiptError::RecoverableCheckError(
tap_core::Error::ReceiptError(tap_core::receipt::ReceiptError::RetryableCheck(
"Recoverable error".to_string()
))
.to_string()
Expand Down

0 comments on commit b609064

Please sign in to comment.