grit_core/error.rs
1//! Library error type (`thiserror`; no `anyhow` in the public API).
2
3use uuid::Uuid;
4
5/// Convenience alias used across the crate.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Everything that can go wrong inside grit-core.
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum Error {
12 /// Underlying SQLite failure.
13 #[error("sqlite: {0}")]
14 Sqlite(#[from] rusqlite::Error),
15
16 /// Op or attribute JSON failed to (de)serialize.
17 #[error("json: {0}")]
18 Json(#[from] serde_json::Error),
19
20 /// Filesystem failure (export/import).
21 #[error("io: {0}")]
22 Io(#[from] std::io::Error),
23
24 /// The writer actor has shut down; the handle is unusable.
25 #[error("grit writer is closed")]
26 Closed,
27
28 /// A referenced node/edge/episode does not exist.
29 #[error("not found: {0}")]
30 NotFound(Uuid),
31
32 /// A stored HLC string failed to parse.
33 #[error("invalid hlc: {0}")]
34 InvalidHlc(String),
35
36 /// The database schema version is newer than this library understands.
37 /// Migrations are forward-only (Design Invariant 8).
38 #[error("db schema version {found} is newer than supported version {supported}")]
39 SchemaTooNew {
40 /// `PRAGMA user_version` found in the file.
41 found: i64,
42 /// Latest version this build can open.
43 supported: i64,
44 },
45
46 /// An op is structurally invalid (e.g. merging a node into itself).
47 #[error("invalid op: {0}")]
48 InvalidOp(String),
49
50 /// Embedding operations before `register_embedding_model`, or a dimension
51 /// mismatch against the registered model.
52 #[error("embedding: {0}")]
53 Embedding(String),
54
55 /// An import line could not be understood.
56 #[error("import: {0}")]
57 Import(String),
58
59 /// A stored row failed to decode (e.g. a malformed uuid) — the database
60 /// contains data grit did not write. Surfaced loudly rather than silently
61 /// dropping the row.
62 #[error("corrupt row: {0}")]
63 Corrupt(String),
64}