use thiserror::Error;
use crate::latent::KindTag;
use crate::time::TimeBase;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("shape mismatch: expected {expected:?}, got {actual:?}")]
Shape {
expected: Vec<usize>,
actual: Vec<usize>,
},
#[error("latent kind mismatch: expected {expected}, got {actual}")]
KindMismatch {
expected: KindTag,
actual: KindTag,
},
#[error("time-base mismatch: {left} vs {right}")]
ClockMismatch {
left: TimeBase,
right: TimeBase,
},
#[error("non-finite value in {context}")]
NonFinite {
context: &'static str,
},
#[error("validation error: {0}")]
Validation(String),
#[error("unsupported: {0}")]
Unsupported(String),
#[error("checkpoint error: {0}")]
Checkpoint(String),
#[error("i/o error: {0}")]
Io(#[from] std::io::Error),
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
#[error("toml error: {0}")]
Toml(#[from] toml::de::Error),
}
impl Error {
pub fn validation(msg: impl std::fmt::Display) -> Self {
Error::Validation(msg.to_string())
}
pub fn shape(expected: impl Into<Vec<usize>>, actual: impl Into<Vec<usize>>) -> Self {
Error::Shape {
expected: expected.into(),
actual: actual.into(),
}
}
}
const _: fn() = || {
fn assert_error_send_sync_static<T: std::error::Error + Send + Sync + 'static>() {}
assert_error_send_sync_static::<Error>();
};