#[derive(Debug)]
pub enum PortableError {
Unsupported(String),
Malformed(String),
Budget(String),
Schema {
found: u32,
min: u32,
max: u32,
},
Json(String),
Io(std::io::Error),
}
impl std::fmt::Display for PortableError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PortableError::Unsupported(msg) => {
write!(f, "figure cannot be exported portably: {msg}")
}
PortableError::Malformed(msg) => write!(f, "malformed portable figure: {msg}"),
PortableError::Budget(msg) => write!(f, "portable figure exceeds a budget: {msg}"),
PortableError::Schema { found, min, max } => write!(
f,
"artifact is schema {found}; this build supports {min}..={max} — \
rendering it would drop content"
),
PortableError::Json(msg) => write!(f, "portable figure spec error: {msg}"),
PortableError::Io(err) => write!(f, "portable figure i/o error: {err}"),
}
}
}
impl std::error::Error for PortableError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
PortableError::Io(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for PortableError {
fn from(err: std::io::Error) -> Self {
PortableError::Io(err)
}
}
impl From<serde_json::Error> for PortableError {
fn from(err: serde_json::Error) -> Self {
PortableError::Json(err.to_string())
}
}