use std::{
error::Error,
fmt::{self, Display, Formatter},
io,
};
#[derive(Debug)]
#[non_exhaustive]
pub enum ArtifactWriteError {
Serialize(serde_json::Error),
Write(io::Error),
TooLarge {
maximum: usize,
},
}
impl Display for ArtifactWriteError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Serialize(error) => write!(formatter, "serialize catalog artifact: {error}"),
Self::Write(error) => write!(formatter, "write catalog artifact: {error}"),
Self::TooLarge { maximum } => {
write!(formatter, "catalog artifact exceeds {maximum} bytes")
}
}
}
}
impl Error for ArtifactWriteError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Serialize(error) => Some(error),
Self::Write(error) => Some(error),
Self::TooLarge { .. } => None,
}
}
}