agent_store/error.rs
1//! Error type for the store substrate.
2
3use thiserror::Error;
4
5/// Errors raised by the store substrate.
6///
7/// Backend-specific failures (rusqlite, and later `postgres`) are flattened
8/// into [`StoreError::Backend`] with a stringified detail, so callers never
9/// have to match on a backend's concrete error type — the substrate is the
10/// boundary.
11#[derive(Debug, Error)]
12pub enum StoreError {
13 /// A backend (SQLite / Postgres) returned an error.
14 #[error("backend error: {0}")]
15 Backend(String),
16
17 /// A [`crate::WriterLog`] chain failed verification — the log has been
18 /// reordered, truncated, or tampered with.
19 #[error("chain broken on stream {stream:?} writer {writer:?} at seq {seq}: {detail}")]
20 ChainBroken {
21 stream: String,
22 writer: String,
23 seq: u64,
24 detail: String,
25 },
26
27 /// A generation counter was asked to move backwards. Generations are
28 /// monotonic by contract — wall-clock time is never a coordination
29 /// primitive here.
30 #[error("non-monotonic generation on {key:?}: current {current}, attempted {attempted}")]
31 NonMonotonicGeneration {
32 key: String,
33 current: u64,
34 attempted: u64,
35 },
36
37 /// A stored value had an unexpected shape (e.g. a hash column that was
38 /// not exactly 32 bytes).
39 #[error("malformed row: {0}")]
40 MalformedRow(String),
41}
42
43/// Convenience alias for results in this crate.
44pub type Result<T> = std::result::Result<T, StoreError>;
45
46impl From<rusqlite::Error> for StoreError {
47 fn from(e: rusqlite::Error) -> Self {
48 StoreError::Backend(e.to_string())
49 }
50}