pub type Result<T> = std::result::Result<T, MindCoreError>;
#[derive(Debug, thiserror::Error)]
pub enum MindCoreError {
#[error("database error: {0}")]
Database(#[from] rusqlite::Error),
#[error("embedding error: {0}")]
Embedding(String),
#[error("model not available: {0}")]
ModelNotAvailable(String),
#[error("serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("model mismatch: stored with '{stored}', current backend is '{current}'")]
ModelMismatch {
stored: String,
current: String,
},
#[error("migration error: {0}")]
Migration(String),
#[cfg(feature = "encryption")]
#[error("encryption error: {0}")]
Encryption(String),
#[error("consolidation error: {0}")]
Consolidation(String),
#[error("llm callback error: {0}")]
LlmCallback(String),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display() {
let err = MindCoreError::Embedding("tensor shape mismatch".into());
assert_eq!(err.to_string(), "embedding error: tensor shape mismatch");
}
#[test]
fn model_mismatch_display() {
let err = MindCoreError::ModelMismatch {
stored: "granite-small-r2".into(),
current: "bge-small-en-v1.5".into(),
};
assert!(err.to_string().contains("granite-small-r2"));
assert!(err.to_string().contains("bge-small-en-v1.5"));
}
#[test]
fn from_rusqlite_error() {
let sqlite_err = rusqlite::Error::QueryReturnedNoRows;
let err: MindCoreError = sqlite_err.into();
matches!(err, MindCoreError::Database(_));
}
#[test]
fn result_type_alias() {
fn returns_ok() -> Result<i32> {
Ok(42)
}
fn returns_err() -> Result<i32> {
Err(MindCoreError::Migration("test".into()))
}
assert!(returns_ok().is_ok());
assert!(returns_err().is_err());
}
}