Skip to content

Commit

Permalink
Merge pull request #31 from malik672/add_recoverable_errors
Browse files Browse the repository at this point in the history
remove redendant code + 0.9.0
  • Loading branch information
malik672 authored Jan 11, 2024
2 parents 034cd2a + cda6467 commit 6854032
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
16 changes: 1 addition & 15 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ use crate::prelude::*;

#[derive(Debug, Error)]
pub enum Error {
#[error("{field} must be greater than 0")]
ChainIdError { field: &'static str },

#[error(transparent)]
ParseError(#[from] std::num::ParseIntError),

#[error("Chain IDs do not match: {0} and {1}")]
ChainIdMismatch(u32, u32),

Expand All @@ -17,18 +11,10 @@ pub enum Error {
#[error("amount has exceeded MAX_UINT256")]
MaxUint,

#[error("Error creating: {0}")]
CreationError(String),

#[error("Can't get the fractional amount: {0}")]
CreateFractionalError(String),

#[error("not equal: {0}")]
NotEqual(String),

#[error("Denominator is 0")]
DenominatorIsZero,

//Custo
#[error("incorrect: {0}")]
Incorrect(String),
}
14 changes: 9 additions & 5 deletions src/utils/sorted_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ pub fn sorted_insert<T: Clone>(
comparator: fn(&T, &T) -> Ordering,
) -> Result<Option<T>, Error> {
if max_size == 0 {
return Err(Error::Incorrect("MAX_SIZE_ZERO".to_owned()));
return Err(Error::Incorrect(
"max_size can't be equal to zero".to_owned(),
));
}

if items.len() > max_size {
return Err(Error::Incorrect("ITEMS_SIZE".to_owned()));
return Err(Error::Incorrect(
"array length cannot exceed max_size".to_string(),
));
}

let removed_item = if items.len() == max_size {
Expand Down Expand Up @@ -47,18 +51,18 @@ mod tests {
}

#[test]
#[should_panic(expected = "MAX_SIZE_ZERO")]
#[should_panic(expected = "max_size can't be equal to zero")]
fn test_max_size_zero() {
let mut arr = Vec::new();
sorted_insert(&mut arr, 1, 0, cmp).unwrap();
}

#[test]
#[should_panic(expected = "ITEMS_SIZE")]
#[should_panic(expected = "array length cannot exceed max_size")]
fn test_length_greater_than_max_size() {
let mut arr = vec![1, 2];
let _w = sorted_insert(&mut arr, 1, 1, cmp).unwrap();
assert!(_w.is_none(), "ITEMS_SIZE");
assert!(_w.is_none(), "array length cannot exceed max_size");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::prelude::*;
///
pub fn sqrt(value: &BigInt) -> Result<BigInt, Error> {
if !value >= Zero::zero() {
return Err(Error::Incorrect("NEGATIVE".to_owned()));
return Err(Error::Incorrect("value cannot be negative".to_string()));
}

// If the value is less than or equal to MAX_SAFE_INTEGER,
Expand Down

0 comments on commit 6854032

Please sign in to comment.