[cache_check (rust)] Add more checks

- Report errors
- Support reading partially broken bitset
  - The output is a bitmap of 2-bit entries, indicating availability of bits
This commit is contained in:
Ming-Hung Tsai
2021-04-20 16:07:25 +08:00
parent 3279d8381b
commit 239ff7dfa1
4 changed files with 129 additions and 33 deletions

View File

@@ -1,4 +1,5 @@
use nom::{multi::count, number::complete::*, IResult};
use std::fmt;
use thiserror::Error;
use crate::checksum;
@@ -52,25 +53,43 @@ pub struct ArrayBlock<V: Unpack> {
#[derive(Error, Clone, Debug)]
pub enum ArrayError {
#[error("io_error")]
//#[error("io_error")]
IoError,
#[error("block error: {0}")]
//#[error("block error: {0}")]
BlockError(String),
#[error("value error: {0}")]
//#[error("value error: {0}")]
ValueError(String),
#[error("aggregate: {0:?}")]
//#[error("aggregate: {0:?}")]
Aggregate(Vec<ArrayError>),
#[error("{0:?}, {1}")]
//#[error("{0:?}, {1}")]
Path(Vec<u64>, Box<ArrayError>),
#[error(transparent)]
BTreeError(#[from] btree::BTreeError),
}
impl fmt::Display for ArrayError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ArrayError::IoError => write!(f, "io error"),
ArrayError::BlockError(msg) => write!(f, "block error: {}", msg),
ArrayError::ValueError(msg) => write!(f, "value error: {}", msg),
ArrayError::Aggregate(errs) => {
for e in errs {
write!(f, "{}", e)?
}
Ok(())
}
ArrayError::Path(path, e) => write!(f, "{} {}", e, btree::encode_node_path(path)),
ArrayError::BTreeError(e) => write!(f, "{}", e),
}
}
}
pub fn array_block_err(path: &[u64], msg: &str) -> ArrayError {
ArrayError::Path(
path.to_vec(),