use thiserror::Error;
#[derive(Error, Debug, PartialEq, Eq)]
pub enum CoreError {
#[error("schema version too new: data version {found}, current supported version {current}")]
SchemaTooNew {
found: u16,
current: u16,
},
#[error("validation failed: {0}")]
Validation(String),
#[error("serialization error: {0}")]
Serialization(String),
#[error("internal error: {0}")]
Internal(String),
}
impl CoreError {
pub fn found_version(&self) -> u16 {
match self {
Self::SchemaTooNew { found, .. } => *found,
_ => 0,
}
}
pub fn current_version(&self) -> u16 {
match self {
Self::SchemaTooNew { current, .. } => *current,
_ => 0,
}
}
}
pub type CoreResult<T> = Result<T, CoreError>;