Skip to content

Commit

Permalink
apply cr
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Apr 7, 2022
1 parent a5254e3 commit d738cb2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
18 changes: 6 additions & 12 deletions fvm/src/blockstore/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -112,28 +106,28 @@ fn cbor_read_header_buf<B: Read>(
} 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 {
Expand Down
2 changes: 1 addition & 1 deletion ipld/amt/src/amt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions ipld/amt/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum Error<E> {
#[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}")]
Expand All @@ -42,17 +42,19 @@ impl<E> From<CborStoreError<E>> for Error<E> {
}
}

/// 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<U, E> {
#[error("user: {0}")]
User(U),
#[error("hamt: {0}")]
Hamt(#[from] Error<E>),
#[error("amt: {0}")]
Amt(#[from] Error<E>),
}

impl<U, E> From<CborStoreError<E>> for EitherError<U, E> {
fn from(err: CborStoreError<E>) -> Self {
EitherError::Hamt(err.into())
EitherError::Amt(err.into())
}
}

Expand Down
2 changes: 2 additions & 0 deletions ipld/hamt/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ impl<E> From<CborStoreError<E>> for Error<E> {
}
}

/// 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<U, E> {
#[error("user: {0}")]
Expand Down

0 comments on commit d738cb2

Please sign in to comment.