use std::{
error::Error,
fmt::{self, Display, Formatter},
};
use crate::client::DecodeError;
#[derive(Debug)]
#[non_exhaustive]
pub enum ArtifactParseError {
Decode(DecodeError),
Structure(serde_json::Error),
UnsupportedSchemaVersion {
found: u32,
},
Invalid {
path: String,
reason: String,
},
}
impl Display for ArtifactParseError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Decode(error) => write!(formatter, "decode catalog artifact: {error}"),
Self::Structure(error) => write!(formatter, "read catalog artifact structure: {error}"),
Self::UnsupportedSchemaVersion { found } => {
write!(
formatter,
"unsupported catalog artifact schema version {found}"
)
}
Self::Invalid { path, reason } => {
write!(formatter, "invalid catalog artifact at {path}: {reason}")
}
}
}
}
impl Error for ArtifactParseError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Decode(error) => Some(error),
Self::Structure(error) => Some(error),
Self::UnsupportedSchemaVersion { .. } | Self::Invalid { .. } => None,
}
}
}