use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum BrainError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("SQLite error: {0}")]
Sqlite(#[from] rusqlite::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("brain not found at {path}")]
BrainNotFound {
path: PathBuf,
},
#[error("invalid brain directory: {path}: {reason}")]
InvalidBrain {
path: PathBuf,
reason: String,
},
#[error("schema version mismatch: found {found}, supported {supported}")]
SchemaVersion {
found: u32,
supported: u32,
},
#[error("mmap format error: {0}")]
MmapFormat(String),
#[error("FTS query error: {0}")]
FtsQuery(String),
#[error("feature not enabled: {0}")]
FeatureDisabled(&'static str),
#[error("AST parse error: {0}")]
Ast(String),
#[error("indexer error: {0}")]
Indexer(String),
#[error("export/import error: {0}")]
Bundle(String),
#[error("{0}")]
Other(String),
}
impl BrainError {
pub fn other(msg: impl Into<String>) -> Self {
Self::Other(msg.into())
}
pub fn mmap(msg: impl Into<String>) -> Self {
Self::MmapFormat(msg.into())
}
pub fn indexer(msg: impl Into<String>) -> Self {
Self::Indexer(msg.into())
}
pub fn bundle(msg: impl Into<String>) -> Self {
Self::Bundle(msg.into())
}
}
pub type Result<T> = std::result::Result<T, BrainError>;