From d738cb29175dd03498279d3b8dc4310adecce30c Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Thu, 7 Apr 2022 11:54:18 +0200 Subject: [PATCH] apply cr --- fvm/src/blockstore/buffered.rs | 18 ++++++------------ ipld/amt/src/amt.rs | 2 +- ipld/amt/src/error.rs | 10 ++++++---- ipld/hamt/src/error.rs | 2 ++ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/fvm/src/blockstore/buffered.rs b/fvm/src/blockstore/buffered.rs index 080b29c71..a70e3c349 100644 --- a/fvm/src/blockstore/buffered.rs +++ b/fvm/src/blockstore/buffered.rs @@ -72,14 +72,8 @@ pub enum FlushError { Io(#[from] std::io::Error), #[error("cid: {0}")] Cid(#[from] cid::Error), - #[error("cbor input was not canonical (lval 24 with value < 24)")] - HeaderLval24, - #[error("cbor input was not canonical (lval 25 with value <= MaxUint8)")] - HeaderLval25, - #[error("cbor input was not canonical (lval 26 with value <= MaxUint16)")] - HeaderLval26, - #[error("cbor input was not canonical (lval 27 with value <= MaxUint32)")] - HeaderLval27, + #[error("cbor input was not canonical (lval {0} with value < {1})")] + HeaderNotCanonical(usize, &'static str), #[error("invalid header cbor_read_header_buf")] HeaderInvalid, #[error("expected cbor type byte string in input")] @@ -112,28 +106,28 @@ fn cbor_read_header_buf( } else if low == 24 { let val = br.read_u8()?; if val < 24 { - return Err(FlushError::HeaderLval24); + return Err(FlushError::HeaderNotCanonical(24, "24")); } Ok((maj, val as usize)) } else if low == 25 { br.read_exact(&mut scratch[..2])?; let val = BigEndian::read_u16(&scratch[..2]); if val <= u8::MAX as u16 { - return Err(FlushError::HeaderLval25); + return Err(FlushError::HeaderNotCanonical(25, "MaxUint8")); } Ok((maj, val as usize)) } else if low == 26 { br.read_exact(&mut scratch[..4])?; let val = BigEndian::read_u32(&scratch[..4]); if val <= u16::MAX as u32 { - return Err(FlushError::HeaderLval26); + return Err(FlushError::HeaderNotCanonical(26, "MaxUint16")); } Ok((maj, val as usize)) } else if low == 27 { br.read_exact(&mut scratch[..8])?; let val = BigEndian::read_u64(&scratch[..8]); if val <= u32::MAX as u64 { - return Err(FlushError::HeaderLval27); + return Err(FlushError::HeaderNotCanonical(27, "MaxUint32")); } Ok((maj, val as usize)) } else { diff --git a/ipld/amt/src/amt.rs b/ipld/amt/src/amt.rs index 195f5b615..718dd3dca 100644 --- a/ipld/amt/src/amt.rs +++ b/ipld/amt/src/amt.rs @@ -254,7 +254,7 @@ where for i in sorted(iter) { let found = self.delete(i)?.is_none(); if strict && found { - return Err(Error::BatchDelteNotFound(i)); + return Err(Error::BatchDeleteNotFound(i)); } modified |= found; } diff --git a/ipld/amt/src/error.rs b/ipld/amt/src/error.rs index 13a2dfb0b..c29cc1d86 100644 --- a/ipld/amt/src/error.rs +++ b/ipld/amt/src/error.rs @@ -26,7 +26,7 @@ pub enum Error { #[error("{0}")] CollapsedNode(#[from] CollapsedNodeError), #[error("no such index {0} in Amt for batch delete")] - BatchDelteNotFound(u64), + BatchDeleteNotFound(u64), #[error("blockstore {0}")] Blockstore(E), #[error("encoding error {0}")] @@ -42,17 +42,19 @@ impl From> for Error { } } +/// This error wraps around around two different errors, either the native `Error` from `amt`, or +/// a custom user error, returned from executing a user defined function. #[derive(Debug, Error)] pub enum EitherError { #[error("user: {0}")] User(U), - #[error("hamt: {0}")] - Hamt(#[from] Error), + #[error("amt: {0}")] + Amt(#[from] Error), } impl From> for EitherError { fn from(err: CborStoreError) -> Self { - EitherError::Hamt(err.into()) + EitherError::Amt(err.into()) } } diff --git a/ipld/hamt/src/error.rs b/ipld/hamt/src/error.rs index cae5e92f8..2b7ad2193 100644 --- a/ipld/hamt/src/error.rs +++ b/ipld/hamt/src/error.rs @@ -30,6 +30,8 @@ impl From> for Error { } } +/// This error wraps around around two different errors, either the native `Error` from `hamt`, or +/// a custom user error, returned from executing a user defined function. #[derive(Debug, Error)] pub enum EitherError { #[error("user: {0}")]