khive_db/error.rs
1//! Error types for the SQLite storage layer.
2
3use std::time::Duration;
4
5use thiserror::Error;
6
7/// Errors produced by the SQLite storage backend.
8#[derive(Debug, Error)]
9pub enum SqliteError {
10 /// Underlying rusqlite driver error.
11 #[error("sqlite error: {0}")]
12 Rusqlite(#[from] rusqlite::Error),
13
14 /// Data invariant violation (corrupt row, unexpected schema state).
15 #[error("invalid data: {0}")]
16 InvalidData(String),
17
18 /// The process-local writer mutex was not acquired within the pool's
19 /// configured finite checkout deadline. This stage happens before SQLite
20 /// executes, so callers must not conflate it with SQLite busy/locked or
21 /// checkpoint starvation.
22 ///
23 /// The display text intentionally retains the historical `InvalidData`
24 /// prefix for compatibility while the variant supplies stable structural
25 /// classification (ADR-135 F6).
26 #[error("invalid data: timed out after {timeout:?} waiting for sqlite writer connection")]
27 WriterPoolCheckoutTimeout {
28 /// Pool checkout deadline that elapsed.
29 timeout: Duration,
30 },
31
32 /// A `PoolConfig` value violated a validated invariant at configuration
33 /// load time (e.g. ADR-131 Decision 2's `write_admission_deadline_ms`
34 /// range). Fires before any connection is opened, and is never silently
35 /// clamped into range.
36 #[error("invalid config: {0}")]
37 InvalidConfig(String),
38
39 /// Filesystem I/O error.
40 #[error("io error: {0}")]
41 Io(#[from] std::io::Error),
42
43 /// A versioned migration failed to apply.
44 #[error("migration v{version} failed: {error}")]
45 Migration {
46 /// The migration version number that failed.
47 version: u32,
48 /// Human-readable description of the failure.
49 error: String,
50 },
51}