use std::fmt::{self, Display, Formatter};
use std::io;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
HashMismatch {
expected: String,
actual: String,
},
HashWrite(io::Error),
Request(Box<ureq::Error>),
Download(io::Error),
Decompress(lzma_rs::error::Error),
Extract(io::Error),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::HashMismatch { expected, actual } => write!(
f,
"file hash {actual} does not match expected hash {expected}"
),
Self::HashWrite(_) => write!(f, "failed to write hash file"),
Self::Request(_) => write!(f, "remote request failed"),
Self::Download(_) => write!(f, "download failed"),
Self::Decompress(_) => write!(f, "tarball decompression failed"),
Self::Extract(_) => write!(f, "tarball extraction failed"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::HashMismatch { .. } => None,
Self::HashWrite(err) => Some(err),
Self::Request(err) => Some(err),
Self::Download(err) => Some(err),
Self::Extract(err) => Some(err),
Self::Decompress(err) => Some(err),
}
}
}