Skip to main content

hydracache_sqlx/
error.rs

1use std::error::Error;
2
3use hydracache_db::DbCacheError;
4use thiserror::Error;
5
6/// Error type returned by SQLx-facing cache helpers.
7#[derive(Debug, Error)]
8pub enum SqlxCacheError {
9    /// The generic database cache adapter or underlying cache failed.
10    #[error(transparent)]
11    Cache(#[from] DbCacheError),
12}
13
14/// SQLx adapter result type.
15pub type Result<T> = std::result::Result<T, SqlxCacheError>;
16
17/// Error returned by SQLx transaction companion helpers.
18#[derive(Debug, Error)]
19pub enum SqlxTransactionError<E>
20where
21    E: Error + Send + Sync + 'static,
22{
23    /// The user-supplied transaction body failed.
24    #[error("SQLx transaction body failed: {0}")]
25    Body(E),
26    /// SQLx failed while beginning, committing, or rolling back the transaction.
27    #[error("SQLx transaction operation failed: {0}")]
28    Sqlx(#[from] sqlx::Error),
29    /// Durable outbox enqueue failed before commit.
30    #[error("SQLx transaction outbox enqueue failed: {0}")]
31    Outbox(#[source] DbCacheError),
32    /// Local non-durable invalidation failed after commit.
33    #[error("SQLx transaction local invalidation failed: {0}")]
34    LocalInvalidation(#[source] hydracache::CacheError),
35    /// Durable mode was requested without an outbox.
36    #[error("SQLx transaction durable mode requires SqlxInvalidationOutbox")]
37    MissingOutbox,
38}
39
40/// SQLx transaction companion result type.
41pub type TransactionResult<T, E> = std::result::Result<T, SqlxTransactionError<E>>;