Skip to content

Commit

Permalink
feat(tap_core)!: Preserve adapter error type using anyhow (#133)
Browse files Browse the repository at this point in the history
Signed-off-by: Ozgur Akkurt <oezgurmakkurt@gmail.com>
  • Loading branch information
ozgrakkurt authored Jul 7, 2023
1 parent a24e1bc commit 77abbd8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions tap_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ethers = "2.0.0"
ethers-core = "2.0.0"
ethers-contract = "2.0.0"
ethers-contract-derive = "2.0.0"
anyhow = "1"

strum = "0.24.1"
strum_macros = "0.24.3"
Expand Down
2 changes: 1 addition & 1 deletion tap_core/src/adapters/rav_storage_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::tap_manager::SignedRAV;

pub trait RAVStorageAdapter {
/// User defined error type;
type AdapterError: std::error::Error + std::fmt::Debug;
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;

fn update_last_rav(&mut self, rav: SignedRAV) -> Result<(), Self::AdapterError>;
fn last_rav(&self) -> Result<Option<SignedRAV>, Self::AdapterError>;
Expand Down
2 changes: 1 addition & 1 deletion tap_core/src/adapters/receipt_storage_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::tap_receipt::ReceivedReceipt;

pub trait ReceiptStorageAdapter {
/// User defined error type;
type AdapterError: std::error::Error + std::fmt::Debug;
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;

fn store_receipt(&mut self, receipt: ReceivedReceipt) -> Result<u64, Self::AdapterError>;
fn retrieve_receipts_in_timestamp_range<R: RangeBounds<u64>>(
Expand Down
4 changes: 2 additions & 2 deletions tap_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub enum Error {
received_rav: ReceiptAggregateVoucher,
expected_rav: ReceiptAggregateVoucher,
},
#[error("Error from adapter: {source_error_message}")]
AdapterError { source_error_message: String },
#[error("Error from adapter.\n Caused by: {source_error}")]
AdapterError { source_error: anyhow::Error },
#[error("Failed to produce rav request, no valid receipts")]
NoValidReceiptsForRAVRequest,
#[error("Previous RAV allocation id ({prev_id}) doesn't match the allocation id from the new receipt ({new_id}).")]
Expand Down
10 changes: 5 additions & 5 deletions tap_core/src/tap_manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<
.receipt_storage_adapter
.store_receipt(received_receipt.clone())
.map_err(|err| Error::AdapterError {
source_error_message: err.to_string(),
source_error: anyhow::Error::new(err),
})?;

received_receipt.perform_checks(
Expand All @@ -101,7 +101,7 @@ impl<
self.receipt_storage_adapter
.update_receipt_by_id(receipt_id, received_receipt)
.map_err(|err| Error::AdapterError {
source_error_message: err.to_string(),
source_error: anyhow::Error::new(err),
})?;
Ok(())
}
Expand Down Expand Up @@ -129,7 +129,7 @@ impl<
self.rav_storage_adapter
.update_last_rav(signed_rav)
.map_err(|err| Error::AdapterError {
source_error_message: err.to_string(),
source_error: anyhow::Error::new(err),
})?;

Ok(())
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<
self.rav_storage_adapter
.last_rav()
.map_err(|err| Error::AdapterError {
source_error_message: err.to_string(),
source_error: anyhow::Error::new(err),
})?;
Ok(previous_rav)
}
Expand All @@ -195,7 +195,7 @@ impl<
.receipt_storage_adapter
.retrieve_receipts_in_timestamp_range(min_timestamp_ns..max_timestamp_ns)
.map_err(|err| Error::AdapterError {
source_error_message: err.to_string(),
source_error: anyhow::Error::new(err),
})?;

let mut accepted_signed_receipts = Vec::<SignedReceipt>::new();
Expand Down

0 comments on commit 77abbd8

Please sign in to comment.