use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Database error")]
SQLite(#[from] rusqlite::Error),
#[error("Inference error: {0}")]
Inference(String),
#[error("Tokenization error: {0}")]
Tokenization(#[from] tokenizers::Error),
#[error("ONNX session error: {0}")]
Onnx(#[from] ort::Error),
#[error("HuggingFace Hub error: {0}")]
HfHub(#[from] hf_hub::api::sync::ApiError),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("Configuration error: {0}")]
Config(String),
#[error("Invalid date/time: {0}")]
Chrono(#[from] chrono::ParseError),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Input cannot be empty")]
EmptyInput,
#[error("Input too long: {actual_length} characters (max: {max_length})")]
InputTooLong {
max_length: usize,
actual_length: usize,
},
#[error("Invalid timestamp format: {timestamp} ({error})")]
InvalidTimestamp { timestamp: String, error: String },
#[error("Memory not found: {0}")]
NotFound(String),
#[error("Database error")]
SqliteModule(String),
#[error("Validation error: {0}")]
Validation(String),
}
impl From<crate::sqlite::Error> for Error {
fn from(err: crate::sqlite::Error) -> Self {
let err_str = err.to_string();
if err_str.contains("No memory found with id:") {
return Error::NotFound("memory not found".to_string());
}
Error::SqliteModule(err_str)
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Error::InvalidInput(s)
}
}