1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum StateError {
8 #[error("Database connection failed: {0}")]
10 Connection(String),
11
12 #[error("Database query failed: {0}")]
14 Query(String),
15
16 #[error("Serialization failed: {0}")]
18 Serialization(String),
19
20 #[error("Deserialization failed: {0}")]
22 Deserialization(String),
23
24 #[error("Commit not found: {0}")]
26 CommitNotFound(String),
27
28 #[error("Branch not found: {0}")]
30 BranchNotFound(String),
31
32 #[error("Invalid commit ID: {0}")]
34 InvalidCommitId(String),
35
36 #[error("Transaction failed: {0}")]
38 Transaction(String),
39
40 #[error("Schema setup failed: {0}")]
42 SchemaSetup(String),
43}
44
45#[derive(Error, Debug)]
47pub enum StorageError {
48 #[error("content not found: {digest}")]
50 NotFound { digest: String },
51
52 #[error("run not found: {run_id}")]
54 RunNotFound { run_id: String },
55
56 #[error("run {run_id} is {status}, expected {expected}")]
58 InvalidRunState {
59 run_id: String,
60 status: String,
61 expected: String,
62 },
63
64 #[error("release not found: {name}")]
66 ReleaseNotFound { name: String },
67
68 #[error("no previous release for '{name}' to roll back to")]
70 NoPreviousRelease { name: String },
71
72 #[error("invalid digest: {digest}")]
74 InvalidDigest { digest: String },
75
76 #[error("integrity error: expected {expected}, got {actual}")]
78 IntegrityError { expected: String, actual: String },
79
80 #[error("storage backend error: {0}")]
82 Backend(String),
83
84 #[error("serialization error: {0}")]
86 Serialization(String),
87}
88
89impl From<surrealdb::Error> for StateError {
90 fn from(err: surrealdb::Error) -> Self {
91 StateError::Query(err.to_string())
92 }
93}
94
95impl From<serde_json::Error> for StateError {
96 fn from(err: serde_json::Error) -> Self {
97 StateError::Serialization(err.to_string())
98 }
99}