From ab1576eaea8cb4cad104f07dc7cf8a9560eb0054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Kr=C3=BCger?= Date: Mon, 4 Sep 2023 12:09:25 +0200 Subject: [PATCH] refactor: Simplify errors now that `iroh_car::Error` is exposed --- car-mirror/src/common.rs | 22 ++++------------------ car-mirror/src/error.rs | 8 ++++---- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/car-mirror/src/common.rs b/car-mirror/src/common.rs index 9fddd0d..20c2054 100644 --- a/car-mirror/src/common.rs +++ b/car-mirror/src/common.rs @@ -1,6 +1,5 @@ #![allow(unknown_lints)] // Because the `instrument` macro contains some `#[allow]`s that rust 1.66 doesn't know yet. -use anyhow::anyhow; use bytes::Bytes; use deterministic_bloom::runtime_size::BloomFilter; use futures::TryStreamExt; @@ -115,11 +114,7 @@ pub async fn block_send( .await?; Ok(CarFile { - bytes: writer - .finish() - .await - .map_err(|e| Error::CarFileError(anyhow!(e)))? - .into(), + bytes: writer.finish().await?.into(), }) } @@ -142,9 +137,7 @@ pub async fn block_receive( let mut dag_verification = IncrementalDagVerification::new([root], store, cache).await?; if let Some(car) = last_car { - let mut reader = CarReader::new(Cursor::new(car.bytes)) - .await - .map_err(|e| Error::CarFileError(anyhow!(e)))?; + let mut reader = CarReader::new(Cursor::new(car.bytes)).await?; read_and_verify_blocks( &mut dag_verification, @@ -305,10 +298,7 @@ async fn write_blocks_into_car( "writing block to CAR", ); - block_bytes += writer - .write(cid, &block) - .await - .map_err(|e| Error::CarFileError(anyhow!(e)))?; + block_bytes += writer.write(cid, &block).await?; if block_bytes > send_minimum { break; @@ -326,11 +316,7 @@ async fn read_and_verify_blocks( cache: &impl Cache, ) -> Result<(), Error> { let mut bytes_read = 0; - while let Some((cid, vec)) = reader - .next_block() - .await - .map_err(|e| Error::CarFileError(anyhow!(e)))? - { + while let Some((cid, vec)) = reader.next_block().await? { let block = Bytes::from(vec); debug!( diff --git a/car-mirror/src/error.rs b/car-mirror/src/error.rs index 221c3d9..1dbc1ac 100644 --- a/car-mirror/src/error.rs +++ b/car-mirror/src/error.rs @@ -50,10 +50,6 @@ pub enum Error { #[error("Error during block parsing: {0}")] ParsingError(anyhow::Error), - /// An error rasied when trying to read or write a CAR file. - #[error("CAR (de)serialization error: {0}")] - CarFileError(anyhow::Error), - /// An error rasied from the blockstore. #[error("BlockStore error: {0}")] BlockStoreError(anyhow::Error), @@ -64,6 +60,10 @@ pub enum Error { /// Errors related to incremental verification #[error(transparent)] IncrementalVerificationError(#[from] IncrementalVerificationError), + + /// An error rasied when trying to read or write a CAR file. + #[error("CAR (de)serialization error: {0}")] + CarFileError(#[from] iroh_car::Error), } /// Errors related to incremental verification