use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq)]
pub enum ModelError {
#[error("invalid snapshot identifier: {0}")]
InvalidSnapshotId(String),
#[error("unsupported schema version: {0}")]
UnsupportedSchemaVersion(String),
#[error("serialization error: {0}")]
SerializationError(String),
#[error("deserialization error: {0}")]
DeserializationError(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_invalid_snapshot_id_error() {
let err = ModelError::InvalidSnapshotId("bad_format".to_string());
assert!(err.to_string().contains("bad_format"));
}
#[test]
fn test_unsupported_schema_version_error() {
let err = ModelError::UnsupportedSchemaVersion("1999.1".to_string());
assert!(err.to_string().contains("1999.1"));
}
#[test]
fn test_serialization_error() {
let err = ModelError::SerializationError("json error".to_string());
assert!(err.to_string().contains("json error"));
}
#[test]
fn test_deserialization_error() {
let err = ModelError::DeserializationError("invalid json".to_string());
assert!(err.to_string().contains("invalid json"));
}
#[test]
fn test_error_clone() {
let err = ModelError::InvalidSnapshotId("test".to_string());
let cloned = err.clone();
assert_eq!(err, cloned);
}
}