foundationdb

Trait RetryableError

Source
pub trait RetryableError:
    Error
    + Send
    + Sync
    + Sized
    + 'static
    + From<FdbError>
    + From<FdbBindingError> {
    // Provided method
    fn retry_decision(&self) -> RetryDecision { ... }
}
Expand description

What the retry loop of crate::Database::run asks of a closure error.

The default retry_decision walks the source() chain looking for an FdbError, so any error type that keeps its FdbError as a source (the idiomatic thiserror #[from]/#[source] pattern) is retry-transparent without overriding anything. Override only to add RetryDecision::Retry arms for app-level retry conditions.

The From bounds let the loop surface its own failures through your type: From<FdbError> supports ? on FdbResult inside the closure, and From<FdbBindingError> carries loop-level failures such as FdbBindingError::ReferenceToTransactionKept.

FdbError itself cannot implement this trait (there is no lossless From<FdbBindingError> for FdbError); use a wrapper type such as FdbBindingError or your own enum.

§Example

use foundationdb::{FdbBindingError, FdbError, RetryableError};

#[derive(Debug)]
enum MyLayerError {
    Fdb(FdbError),
    Binding(FdbBindingError),
    InvalidDocument,
}

impl std::fmt::Display for MyLayerError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{self:?}")
    }
}

impl std::error::Error for MyLayerError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Fdb(e) => Some(e),
            Self::Binding(e) => Some(e),
            Self::InvalidDocument => None,
        }
    }
}

impl From<FdbError> for MyLayerError {
    fn from(e: FdbError) -> Self {
        Self::Fdb(e)
    }
}

impl From<FdbBindingError> for MyLayerError {
    fn from(e: FdbBindingError) -> Self {
        Self::Binding(e)
    }
}

// The default source() walk makes wrapped FdbErrors retryable.
impl RetryableError for MyLayerError {}

Provided Methods§

Source

fn retry_decision(&self) -> RetryDecision

Classifies this error for the retry loop.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl RetryableError for FdbBindingError

Source§

impl RetryableError for RankedRegisterError

The source() chain exposes the wrapped FdbError, so the default retry_decision makes this error retry-transparent in db.run.