Skip to main content

agentdb/
error.rs

1use thiserror::Error;
2
3/// All errors that AgentDB operations can produce.
4///
5/// Every public API function returns [`Result<T>`] which aliases
6/// `std::result::Result<T, AgentDbError>`.
7#[derive(Debug, Error)]
8pub enum AgentDbError {
9    /// Underlying SQLite operation failed.
10    #[error("SQLite error: {0}")]
11    Sqlite(#[from] rusqlite::Error),
12
13    /// JSON (de)serialization failed; the message describes what went wrong.
14    #[error("Serialization error: {0}")]
15    Serialization(String),
16
17    /// The named vector collection does not exist in the database.
18    #[error("Collection not found: {0}")]
19    CollectionNotFound(String),
20
21    /// The caller supplied a vector whose length differs from the collection's
22    /// declared dimensionality.
23    #[error("Dimension mismatch: expected {expected}, got {got}")]
24    DimensionMismatch { expected: usize, got: usize },
25
26    /// A memory graph node with the given ID does not exist.
27    #[error("Node not found: {0}")]
28    NodeNotFound(String),
29
30    /// A directed edge between the given nodes does not exist.
31    #[error("Edge not found: {src} -> {dst}")]
32    EdgeNotFound { src: String, dst: String },
33
34    /// The on-disk schema version is newer or older than this library expects.
35    /// Run `agentdb migrate` to bring the database up to date.
36    #[error("Schema version mismatch: run agentdb migrate")]
37    SchemaMigration,
38
39    /// Low-level database corruption was detected (checksum failure,
40    /// unexpected NULL in a required column, etc.).
41    #[error("Database corrupted: {0}")]
42    Corruption(String),
43
44    /// A caller-supplied argument was out of range or otherwise invalid.
45    #[error("Invalid argument: {0}")]
46    InvalidArgument(String),
47}
48
49/// Convenience alias — all AgentDB public APIs return this type.
50pub type Result<T> = std::result::Result<T, AgentDbError>;