Skip to content

Commit d0369ed

Browse files
committed
refactor: add description to errors
1 parent b510d33 commit d0369ed

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

aggregation_mode/src/backend/fetcher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use tracing::{error, info};
1717

1818
#[derive(Debug)]
1919
pub enum ProofsFetcherError {
20-
QueryingLogs,
21-
BlockNumber,
20+
GetLogs(String),
21+
GetBlockNumber(String),
2222
}
2323

2424
pub struct ProofsFetcher {
@@ -59,7 +59,7 @@ impl ProofsFetcher {
5959
.from_block(from_block)
6060
.query()
6161
.await
62-
.map_err(|_| ProofsFetcherError::QueryingLogs)?;
62+
.map_err(|e| ProofsFetcherError::GetLogs(e.to_string()))?;
6363

6464
info!("Logs collected {}", logs.len());
6565

@@ -124,7 +124,7 @@ impl ProofsFetcher {
124124
.rpc_provider
125125
.get_block_number()
126126
.await
127-
.map_err(|_| ProofsFetcherError::BlockNumber)?;
127+
.map_err(|e| ProofsFetcherError::GetBlockNumber(e.to_string()))?;
128128

129129
let number_of_blocks_in_the_past = self.fetch_from_secs_ago / self.block_time_secs;
130130

aggregation_mode/src/backend/s3.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use aligned_sdk::core::types::VerificationData;
22

33
#[derive(Debug)]
44
pub enum GetBatchProofsError {
5-
Fetching,
6-
Deserialization,
7-
EmptyBody,
8-
StatusFailed,
9-
ReqwestClientFailed,
5+
FetchingS3Batch(String),
6+
Deserialization(String),
7+
EmptyBody(String),
8+
StatusFailed(String),
9+
ReqwestClientFailed((u16, String)),
1010
}
1111

1212
// needed to make S3 bucket work
@@ -18,25 +18,28 @@ pub async fn get_aligned_batch_from_s3(
1818
let client = reqwest::Client::builder()
1919
.user_agent(DEFAULT_USER_AGENT)
2020
.build()
21-
.map_err(|_| GetBatchProofsError::ReqwestClientFailed)?;
21+
.map_err(|e| GetBatchProofsError::ReqwestClientFailed(e.to_string()))?;
2222

2323
let response = client
2424
.get(url)
2525
.send()
2626
.await
27-
.map_err(|_| GetBatchProofsError::Fetching)?;
27+
.map_err(|e| GetBatchProofsError::FetchingS3Batch(e.to_string()))?;
2828
if !response.status().is_success() {
29-
return Err(GetBatchProofsError::StatusFailed);
29+
return Err(GetBatchProofsError::StatusFailed((
30+
response.status().as_u16(),
31+
response.status().canonical_reason(),
32+
)));
3033
}
3134

3235
let bytes = response
3336
.bytes()
3437
.await
35-
.map_err(|_| GetBatchProofsError::EmptyBody)?;
38+
.map_err(|e| GetBatchProofsError::EmptyBody(e.to_string()))?;
3639
let bytes: &[u8] = bytes.iter().as_slice();
3740

38-
let data: Vec<VerificationData> =
39-
ciborium::from_reader(bytes).map_err(|_| GetBatchProofsError::Deserialization)?;
41+
let data: Vec<VerificationData> = ciborium::from_reader(bytes)
42+
.map_err(|e| GetBatchProofsError::Deserialization(e.to_string()))?;
4043

4144
Ok(data)
4245
}

0 commit comments

Comments
 (0)