Skip to content

Commit

Permalink
Implement error handling for chunker and id
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsan committed May 3, 2023
1 parent e8e56e4 commit 8adc164
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions crates/rustic_core/src/chunker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use std::io::{self, Read};

use rand::{thread_rng, Rng};

use crate::{cdc::polynom::{Polynom, Polynom64}, RusticResult};
use crate::cdc::rolling_hash::{Rabin64, RollingHash64};
use crate::{
cdc::polynom::{Polynom, Polynom64},
RusticErrorKind, RusticResult,
};

use crate::error::PolynomialErrorKind;

Expand Down Expand Up @@ -148,7 +151,7 @@ pub fn random_poly() -> RusticResult<u64> {
return Ok(poly);
}
}
Err(PolynomialErrorKind::NoSuitablePolynomialFound)
Err(RusticErrorKind::PolynomialError(PolynomialErrorKind::NoSuitablePolynomialFound).into())
}

pub trait PolynomExtend {
Expand Down
5 changes: 3 additions & 2 deletions crates/rustic_core/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt;
use std::ops::Deref;
use std::path::Path;

use crate::{error::IdErrorKind, RusticResult};
use crate::{error::IdErrorKind, RusticErrorKind, RusticResult};
use binrw::{BinRead, BinWrite};
use derive_more::{Constructor, Display};
use rand::{thread_rng, RngCore};
Expand Down Expand Up @@ -39,7 +39,8 @@ impl Id {
pub fn from_hex(s: &str) -> RusticResult<Self> {
let mut id = Self::default();

hex::decode_to_slice(s, &mut id.0).map_err(IdErrorKind::HexError)?;
hex::decode_to_slice(s, &mut id.0)
.map_err(|err| RusticErrorKind::IdError(IdErrorKind::HexError(err)))?;

Ok(id)
}
Expand Down

0 comments on commit 8adc164

Please sign in to comment.