mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Add BlockErrorKind classification enum
Add a small, stable enum that classifies block errors into broad categories - I/O, invalid format, unsupported feature, corrupt image, out of bounds, not found, overflow. Callers match on this for control flow rather than on format specific error variants. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
f184a0f0f3
commit
e4e74a9d93
@@ -15,3 +15,42 @@
|
||||
//! |-- VhdError / RawError / ...
|
||||
//! +-- io::Error / etc.
|
||||
//! ```
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
|
||||
/// Small, stable classification of block errors.
|
||||
///
|
||||
/// Callers match on this for control flow. Adding new format specific
|
||||
/// errors does not require new variants here.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum BlockErrorKind {
|
||||
/// An underlying I/O operation failed.
|
||||
Io,
|
||||
/// The disk image format is structurally invalid.
|
||||
InvalidFormat,
|
||||
/// The disk image requires a feature that is not implemented.
|
||||
UnsupportedFeature,
|
||||
/// The image is marked or detected as corrupt.
|
||||
CorruptImage,
|
||||
/// An address, offset, or index is outside the valid range.
|
||||
OutOfBounds,
|
||||
/// A file or required internal structure could not be found.
|
||||
NotFound,
|
||||
/// An internal counter or limit was exceeded.
|
||||
Overflow,
|
||||
}
|
||||
|
||||
impl Display for BlockErrorKind {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Io => write!(f, "I/O error"),
|
||||
Self::InvalidFormat => write!(f, "invalid format"),
|
||||
Self::UnsupportedFeature => write!(f, "unsupported feature"),
|
||||
Self::CorruptImage => write!(f, "corrupt image"),
|
||||
Self::OutOfBounds => write!(f, "out of bounds"),
|
||||
Self::NotFound => write!(f, "not found"),
|
||||
Self::Overflow => write!(f, "overflow"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user