Skip to main content

oxidized_state/
error.rs

1//! Error types for oxidized-state
2
3use thiserror::Error;
4
5/// Errors that can occur in the state persistence layer
6#[derive(Error, Debug)]
7pub enum StateError {
8    /// Database connection error
9    #[error("Database connection failed: {0}")]
10    Connection(String),
11
12    /// Database query error
13    #[error("Database query failed: {0}")]
14    Query(String),
15
16    /// Serialization error
17    #[error("Serialization failed: {0}")]
18    Serialization(String),
19
20    /// Deserialization error
21    #[error("Deserialization failed: {0}")]
22    Deserialization(String),
23
24    /// Commit not found
25    #[error("Commit not found: {0}")]
26    CommitNotFound(String),
27
28    /// Branch not found
29    #[error("Branch not found: {0}")]
30    BranchNotFound(String),
31
32    /// Invalid commit ID format
33    #[error("Invalid commit ID: {0}")]
34    InvalidCommitId(String),
35
36    /// Transaction failed
37    #[error("Transaction failed: {0}")]
38    Transaction(String),
39
40    /// Schema setup error
41    #[error("Schema setup failed: {0}")]
42    SchemaSetup(String),
43}
44
45/// Errors for the storage trait abstractions (CasStore, RunLedger, ReleaseRegistry)
46#[derive(Error, Debug)]
47pub enum StorageError {
48    /// Content not found in CAS
49    #[error("content not found: {digest}")]
50    NotFound { digest: String },
51
52    /// Run not found in ledger
53    #[error("run not found: {run_id}")]
54    RunNotFound { run_id: String },
55
56    /// Run is not in a valid state for the requested operation
57    #[error("run {run_id} is {status}, expected {expected}")]
58    InvalidRunState {
59        run_id: String,
60        status: String,
61        expected: String,
62    },
63
64    /// Release not found in registry
65    #[error("release not found: {name}")]
66    ReleaseNotFound { name: String },
67
68    /// No previous release to roll back to
69    #[error("no previous release for '{name}' to roll back to")]
70    NoPreviousRelease { name: String },
71
72    /// Invalid digest string (not valid 64-char hex)
73    #[error("invalid digest: {digest}")]
74    InvalidDigest { digest: String },
75
76    /// Data integrity violation
77    #[error("integrity error: expected {expected}, got {actual}")]
78    IntegrityError { expected: String, actual: String },
79
80    /// Backend I/O error
81    #[error("storage backend error: {0}")]
82    Backend(String),
83
84    /// Serialization/deserialization error
85    #[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}