Skip to content

Commit c0a87c3

Browse files
authored
refactor(core): move error to separate module (#104)
Signed-off-by: Ozgur Akkurt <[email protected]>
1 parent 9819c8b commit c0a87c3

File tree

3 files changed

+48
-36
lines changed

3 files changed

+48
-36
lines changed

tap_core/src/eip_712_signed_message.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
//! Module containing EIP712 message and signature
55
//!
66
7+
use ethereum_types::Address;
78
use ethers::{
89
signers::{LocalWallet, Signer},
910
types::Signature,
1011
};
11-
use ethers_core::types::{transaction::eip712, Address};
12+
use ethers_core::types::transaction::eip712;
1213
use serde::{Deserialize, Serialize};
1314

1415
use crate::{Error, Result};

tap_core/src/error.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2023-, Semiotic AI, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Module containing Error type and Result typedef
5+
//!
6+
7+
use crate::receipt_aggregate_voucher::ReceiptAggregateVoucher;
8+
use ethers::signers::WalletError;
9+
use ethers_core::{abi::Address, types::SignatureError};
10+
use std::result::Result as StdResult;
11+
use thiserror::Error as ThisError;
12+
13+
#[derive(ThisError, Debug)]
14+
pub enum Error {
15+
#[error("Aggregating receipt results in overflow")]
16+
AggregateOverflow,
17+
#[error("Failed to encode to EIP712 hash:\n{source_error_message}")]
18+
EIP712EncodeError { source_error_message: String },
19+
#[error(
20+
"Unexpected check: {check_string}, only checks provided in initial checklist are valid"
21+
)]
22+
InvalidCheckError { check_string: String },
23+
#[error("The requested action is invalid for current receipt state: {state}")]
24+
InvalidStateForRequestedAction { state: String },
25+
#[error("Failed to get current system time: {source_error_message} ")]
26+
InvalidSystemTime { source_error_message: String },
27+
#[error(transparent)]
28+
WalletError(#[from] WalletError),
29+
#[error(transparent)]
30+
SignatureError(#[from] SignatureError),
31+
#[error("Recovered gateway address invalid{address}")]
32+
InvalidRecoveredSigner { address: Address },
33+
#[error("Received RAV does not match expexted RAV")]
34+
InvalidReceivedRAV {
35+
received_rav: ReceiptAggregateVoucher,
36+
expected_rav: ReceiptAggregateVoucher,
37+
},
38+
#[error("Error from adapter: {source_error_message}")]
39+
AdapterError { source_error_message: String },
40+
#[error("Failed to produce rav request, no valid receipts")]
41+
NoValidReceiptsForRAVRequest,
42+
}
43+
44+
pub type Result<T> = StdResult<T, Error>;

tap_core/src/lib.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,16 @@
88
99
use std::time::{SystemTime, UNIX_EPOCH};
1010

11-
use ethereum_types::Address;
12-
use ethers::{signers::WalletError, types::SignatureError};
13-
use receipt_aggregate_voucher::ReceiptAggregateVoucher;
1411
use thiserror::Error;
1512

1613
pub mod adapters;
1714
pub mod eip_712_signed_message;
15+
mod error;
1816
pub mod receipt_aggregate_voucher;
1917
pub mod tap_manager;
2018
pub mod tap_receipt;
2119

22-
#[derive(Error, Debug)]
23-
24-
pub enum Error {
25-
#[error("Aggregating receipt results in overflow")]
26-
AggregateOverflow,
27-
#[error("Failed to encode to EIP712 hash:\n{source_error_message}")]
28-
EIP712EncodeError { source_error_message: String },
29-
#[error(
30-
"Unexpected check: {check_string}, only checks provided in initial checklist are valid"
31-
)]
32-
InvalidCheckError { check_string: String },
33-
#[error("The requested action is invalid for current receipt state: {state}")]
34-
InvalidStateForRequestedAction { state: String },
35-
#[error("Failed to get current system time: {source_error_message} ")]
36-
InvalidSystemTime { source_error_message: String },
37-
#[error(transparent)]
38-
WalletError(#[from] WalletError),
39-
#[error(transparent)]
40-
SignatureError(#[from] SignatureError),
41-
#[error("Recovered gateway address invalid{address}")]
42-
InvalidRecoveredSigner { address: Address },
43-
#[error("Received RAV does not match expexted RAV")]
44-
InvalidReceivedRAV {
45-
received_rav: ReceiptAggregateVoucher,
46-
expected_rav: ReceiptAggregateVoucher,
47-
},
48-
#[error("Error from adapter: {source_error_message}")]
49-
AdapterError { source_error_message: String },
50-
#[error("Failed to produce rav request, no valid receipts")]
51-
NoValidReceiptsForRAVRequest,
52-
}
53-
type Result<T> = std::result::Result<T, Error>;
20+
pub use error::{Error, Result};
5421

5522
pub(crate) fn get_current_timestamp_u64_ns() -> Result<u64> {
5623
Ok(SystemTime::now()

0 commit comments

Comments
 (0)