Merge pull request #747 from zcash/FsBlockDbError_display

Implement fmt::Display descriptions for FsBlockDbError
This commit is contained in:
str4d 2023-01-04 08:15:39 +00:00 committed by GitHub
commit 268754d635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 0 deletions

View File

@ -951,6 +951,51 @@ impl BlockSource for FsBlockDb {
}
}
#[cfg(feature = "unstable")]
impl std::fmt::Display for FsBlockDbError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
FsBlockDbError::Fs(io_error) => {
write!(f, "Failed to access the file system: {}", io_error)
}
FsBlockDbError::Db(e) => {
write!(f, "There was a problem with the sqlite db: {}", e)
}
FsBlockDbError::Protobuf(e) => {
write!(f, "Failed to parse protobuf-encoded record: {}", e)
}
FsBlockDbError::MissingBlockPath(block_path) => {
write!(
f,
"CompactBlock file expected but not found at {}",
block_path.display(),
)
}
FsBlockDbError::InvalidBlockstoreRoot(fsblockdb_root) => {
write!(
f,
"The block storage root {} is not a directory",
fsblockdb_root.display(),
)
}
FsBlockDbError::InvalidBlockPath(block_path) => {
write!(
f,
"CompactBlock path {} is not a file",
block_path.display(),
)
}
FsBlockDbError::CorruptedData(e) => {
write!(
f,
"The block cache has corrupted data and this caused an error: {}",
e,
)
}
}
}
}
#[cfg(test)]
#[macro_use]
extern crate assert_matches;