use core::fmt;
use crate::detect::{BlockFormat, FatVariant, PartitionTableKind};
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Io(hadris_io::Error),
UnknownFormat,
PartitionedDisk(PartitionTableKind),
UnsupportedFormat(BlockFormat),
DetectedFormatMismatch {
detected: FatVariant,
opened: FatVariant,
},
Fat(hadris_fat::Error),
}
pub type Result<T> = core::result::Result<T, Error>;
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(error) => write!(formatter, "block detection I/O error: {error}"),
Self::UnknownFormat => formatter.write_str("unknown block volume format"),
Self::PartitionedDisk(kind) => write!(
formatter,
"{kind:?} disk must be opened through a partition view"
),
Self::UnsupportedFormat(format) => {
write!(formatter, "unsupported block format: {format:?}")
}
Self::DetectedFormatMismatch { detected, opened } => write!(
formatter,
"detected {detected:?}, but full validation opened {opened:?}"
),
Self::Fat(error) => write!(formatter, "FAT open failed: {error}"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
impl From<hadris_io::Error> for Error {
fn from(error: hadris_io::Error) -> Self {
Self::Io(error)
}
}
impl From<hadris_fat::Error> for Error {
fn from(error: hadris_fat::Error) -> Self {
Self::Fat(error)
}
}