use thiserror::Error;
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum CoreError {
#[error("id parse error: {0}")]
IdParse(String),
#[error("schema version mismatch: found {found}, expected {expected}")]
SchemaMismatch {
found: u16,
expected: u16,
},
#[error("json validation failed: {0}")]
JsonValidation(String),
#[error("validation failed: {0}")]
Validation(String),
}
pub type CoreResult<T> = Result<T, CoreError>;
pub use CoreError as CortexError;
pub type CortexResult<T> = CoreResult<T>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn schema_mismatch_renders_clean_message() {
let e = CoreError::SchemaMismatch {
found: 2,
expected: 1,
};
assert_eq!(
e.to_string(),
"schema version mismatch: found 2, expected 1"
);
}
#[test]
fn id_parse_renders_clean_message() {
let e = CoreError::IdParse("bad".into());
assert_eq!(e.to_string(), "id parse error: bad");
}
}