use std::io;
#[derive(Debug)]
pub enum Error {
Io(io::Error),
OutOfBounds { offset: u64, len: u64, size: u64 },
InvalidImage(String),
Unsupported(String),
InvalidArgument(String),
Streaming {
kind: &'static str,
op: &'static str,
},
Immutable {
kind: &'static str,
op: &'static str,
},
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Io(e) => write!(f, "io: {e}"),
Error::OutOfBounds { offset, len, size } => write!(
f,
"out of bounds: offset {offset} len {len} exceeds device size {size}"
),
Error::InvalidImage(m) => write!(f, "invalid image: {m}"),
Error::Unsupported(m) => write!(f, "unsupported feature: {m}"),
Error::InvalidArgument(m) => write!(f, "invalid argument: {m}"),
Error::Streaming { kind, op } => write!(
f,
"{op}: {kind} is a streaming format — use `fstool repack` to produce a new one"
),
Error::Immutable { kind, op } => write!(
f,
"{op}: {kind} is a write-once format — use `fstool repack` to rebuild it"
),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
_ => None,
}
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::Io(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;