use thiserror::Error;
#[derive(Error, Debug)]
pub enum StateError {
#[error("Database connection failed: {0}")]
Connection(String),
#[error("Database query failed: {0}")]
Query(String),
#[error("Serialization failed: {0}")]
Serialization(String),
#[error("Deserialization failed: {0}")]
Deserialization(String),
#[error("Commit not found: {0}")]
CommitNotFound(String),
#[error("Branch not found: {0}")]
BranchNotFound(String),
#[error("Invalid commit ID: {0}")]
InvalidCommitId(String),
#[error("Transaction failed: {0}")]
Transaction(String),
#[error("Schema setup failed: {0}")]
SchemaSetup(String),
}
#[derive(Error, Debug)]
pub enum StorageError {
#[error("content not found: {digest}")]
NotFound { digest: String },
#[error("run not found: {run_id}")]
RunNotFound { run_id: String },
#[error("run {run_id} is {status}, expected {expected}")]
InvalidRunState {
run_id: String,
status: String,
expected: String,
},
#[error("release not found: {name}")]
ReleaseNotFound { name: String },
#[error("no previous release for '{name}' to roll back to")]
NoPreviousRelease { name: String },
#[error("invalid digest: {digest}")]
InvalidDigest { digest: String },
#[error("integrity error: expected {expected}, got {actual}")]
IntegrityError { expected: String, actual: String },
#[error("storage backend error: {0}")]
Backend(String),
#[error("serialization error: {0}")]
Serialization(String),
}
impl From<surrealdb::Error> for StateError {
fn from(err: surrealdb::Error) -> Self {
StateError::Query(err.to_string())
}
}
impl From<serde_json::Error> for StateError {
fn from(err: serde_json::Error) -> Self {
StateError::Serialization(err.to_string())
}
}