Skip to main content

kindling_store/
error.rs

1use kindling_types::Id;
2
3/// Errors produced by the SQLite store.
4#[derive(Debug, thiserror::Error)]
5pub enum StoreError {
6    #[error("sqlite error: {0}")]
7    Sqlite(#[from] rusqlite::Error),
8
9    #[error("json (de)serialization error: {0}")]
10    Json(#[from] serde_json::Error),
11
12    #[error("io error: {0}")]
13    Io(#[from] std::io::Error),
14
15    #[error("capsule {0} not found or already closed")]
16    CapsuleNotOpen(Id),
17
18    #[error("summary {summary_id} not found for capsule {capsule_id}")]
19    SummaryNotFound { summary_id: Id, capsule_id: Id },
20
21    #[error("pin {0} not found")]
22    PinNotFound(Id),
23
24    #[error("observation {0} not found")]
25    ObservationNotFound(Id),
26
27    #[error(
28        "database schema version {found} is below the minimum compatible version \
29         {min_compatible} — run the TypeScript migration runner to upgrade it"
30    )]
31    SchemaTooOld { found: i64, min_compatible: i64 },
32
33    #[error(
34        "database schema version {found} is newer than the supported version {supported} — \
35         upgrade this kindling binary"
36    )]
37    SchemaTooNew { found: i64, supported: i64 },
38
39    #[error("database has no schema and the connection is read-only")]
40    UninitializedDatabase,
41
42    #[error("unexpected value {value:?} in column {column}")]
43    UnexpectedRowValue { column: &'static str, value: String },
44}
45
46pub type StoreResult<T> = Result<T, StoreError>;