#[derive(Debug, thiserror::Error)]
pub enum MemoryError {
#[error("memory_20250818 rate limit exceeded: {limit} calls/quest")]
RateLimit { limit: u32 },
#[error("invalid memory path '{0}': path traversal or invalid prefix")]
PathInvalid(String),
#[error("memory path not found: '{0}'")]
PathNotFound(String),
#[error("memory path already exists: '{path}'")]
PathExists { path: String },
#[error("redb backend error: {0}")]
Redb(String),
#[error("memory I/O error: {reason}")]
Io { reason: String },
#[error("str_replace: old_str not found in '{path}'")]
OldStrNotFound { path: String },
#[error("insert: line {line} out of range in '{path}'")]
InsertOutOfRange { path: String, line: u32 },
#[error(
"invalid view_range [{start}, {end}]: start > end or end exceeds content length ({len} lines)"
)]
RangeInvalid {
start: usize,
end: usize,
len: usize,
},
}
impl From<redb::Error> for MemoryError {
fn from(e: redb::Error) -> Self {
Self::Redb(e.to_string())
}
}
impl From<redb::DatabaseError> for MemoryError {
fn from(e: redb::DatabaseError) -> Self {
Self::Redb(e.to_string())
}
}
impl From<redb::TransactionError> for MemoryError {
fn from(e: redb::TransactionError) -> Self {
Self::Redb(e.to_string())
}
}
impl From<redb::StorageError> for MemoryError {
fn from(e: redb::StorageError) -> Self {
Self::Redb(e.to_string())
}
}
impl From<redb::TableError> for MemoryError {
fn from(e: redb::TableError) -> Self {
Self::Redb(e.to_string())
}
}
impl From<redb::CommitError> for MemoryError {
fn from(e: redb::CommitError) -> Self {
Self::Redb(e.to_string())
}
}