claw_core/error.rs
1//! Error types for claw-core.
2//!
3//! All public API errors are represented by [`ClawError`], a typed enum
4//! backed by [`thiserror`]. Downstream crates should match on [`ClawError`]
5//! variants rather than on the underlying error sources.
6
7use thiserror::Error;
8
9/// The unified error type for claw-core operations.
10#[derive(Debug, Error)]
11pub enum ClawError {
12 /// An underlying SQLx database error occurred.
13 #[error("database error: {0}")]
14 Database(#[from] sqlx::Error),
15
16 /// A migration step failed.
17 #[error("migration error: {0}")]
18 Migration(String),
19
20 /// Configuration validation failed.
21 #[error("configuration error: {0}")]
22 Config(String),
23
24 /// The requested record was not found.
25 #[error("{entity} with id '{id}' not found")]
26 NotFound {
27 /// The entity type that was not found.
28 entity: String,
29 /// The identifier that was searched for.
30 id: String,
31 },
32
33 /// A unique constraint violation occurred.
34 #[error("{entity} with id '{id}' already exists")]
35 Conflict {
36 /// The entity type that already exists.
37 entity: String,
38 /// The conflicting identifier.
39 id: String,
40 },
41
42 /// A serialization or deserialization error occurred.
43 #[error("serialization error: {0}")]
44 Serialization(#[from] serde_json::Error),
45
46 /// A snapshot operation failed.
47 #[error("snapshot error: {0}")]
48 Snapshot(String),
49
50 /// Snapshot checksum verification failed.
51 #[error("snapshot corrupt: {0}")]
52 SnapshotCorrupt(String),
53
54 /// A transaction operation failed.
55 #[error("transaction error: {0}")]
56 Transaction(String),
57
58 /// A cache operation failed.
59 #[error("cache error: {0}")]
60 Cache(String),
61
62 /// The caller supplied invalid input.
63 #[error("invalid input: {0}")]
64 InvalidInput(String),
65
66 /// An I/O error occurred (e.g. while managing snapshot files).
67 #[error("I/O error: {0}")]
68 IoError(#[from] std::io::Error),
69
70 /// A store operation failed.
71 #[error("store error: {0}")]
72 Store(String),
73
74 /// An index operation failed.
75 #[error("index error: {0}")]
76 Index(String),
77
78 /// An unexpected internal error occurred.
79 #[error("internal error: {0}")]
80 Internal(String),
81}
82
83/// Convenience alias for `Result<T, ClawError>`.
84pub type ClawResult<T> = Result<T, ClawError>;