#![allow(missing_docs)]
use crate::types::UnitId;
#[macro_export]
macro_rules! impl_redb_store_errors {
($err_type:ty, $variant:ident) => {
impl From<redb::DatabaseError> for $err_type {
fn from(e: redb::DatabaseError) -> Self { Self::$variant(e.to_string()) }
}
impl From<redb::TableError> for $err_type {
fn from(e: redb::TableError) -> Self { Self::$variant(e.to_string()) }
}
impl From<redb::StorageError> for $err_type {
fn from(e: redb::StorageError) -> Self { Self::$variant(e.to_string()) }
}
impl From<redb::TransactionError> for $err_type {
fn from(e: redb::TransactionError) -> Self { Self::$variant(e.to_string()) }
}
impl From<redb::CommitError> for $err_type {
fn from(e: redb::CommitError) -> Self { Self::$variant(e.to_string()) }
}
};
($err_type:ty, $variant:ident, +toplevel) => {
impl From<redb::Error> for $err_type {
fn from(e: redb::Error) -> Self { Self::$variant(e.to_string()) }
}
$crate::impl_redb_store_errors!($err_type, $variant);
};
}
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum SomaError {
#[error("Invalid transition: {from_unit} → {to_unit} (expected {from_unit} → {expected})")]
InvalidTransition {
from_unit: UnitId,
to_unit: UnitId,
expected: UnitId,
},
#[error("Ring is not initialized — genesis has not occurred")]
RingNotInitialized,
#[error("Genesis has already started — ring is no longer uninitialized")]
GenesisAlreadyStarted,
#[error("Genesis is not in progress — cannot close ring")]
GenesisNotInProgress,
#[error("Genesis pipeline is already complete — all units processed")]
GenesisAlreadyComplete,
#[error("Genesis out of order: expected {expected}, received {received}")]
GenesisOutOfOrder { expected: UnitId, received: UnitId },
#[error("Genesis pipeline incomplete — not all units have been processed")]
GenesisPipelineIncomplete,
#[error("Genesis already recorded in the temporal ledger")]
GenesisAlreadyRecorded,
#[error("Temporal ledger is empty — record genesis first")]
LedgerEmpty,
#[error("Chain integrity violation at cycle {cycle_index}")]
ChainIntegrityViolation { cycle_index: u64 },
#[error("Envelope validation failed: {reason}")]
EnvelopeInvalid { reason: String },
#[error("Cycle timeout: {elapsed_ms}ms exceeds Δt_max={max_ms}ms")]
CycleTimeout { elapsed_ms: u64, max_ms: u64 },
}