@shinyaz

aurora-dsql-sqlx-connector's retry_on_occ requires sqlx::Error

1 min read

While using the Aurora DSQL Rust connector's retry_on_occ, I wrote the closure return as Ok::<_, anyhow::Error>(()) and got a compile error.

Output
expected `sqlx::Error`, found `anyhow::Error`

Looking at the retry_on_occ signature, the closure's Future must return Result<T, sqlx::Error>.

Rust (signature)
pub async fn retry_on_occ<F, Fut, T>(config: &OCCRetryConfig, mut f: F) -> Result<T>
where
    F: FnMut() -> Fut,
    Fut: std::future::Future<Output = std::result::Result<T, sqlx::Error>>,

However, retry_on_occ itself returns Result<T, DsqlError>. So there are two error type layers:

  • Inside the closure: sqlx::Error (standard SQLx error)
  • Return of retry_on_occ: DsqlError (wraps as DsqlError::OCCRetryExhausted on retry exhaustion)

Inside the closure, just propagate sqlx::Error with ?. Convert to anyhow outside retry_on_occ.

Rust
let result: Result<(), DsqlError> = retry_on_occ(&config, || async {
    let mut tx = pool.begin().await?; // propagate sqlx::Error with ?
    sqlx::query("...").execute(&mut *tx).await?;
    tx.commit().await?;
    Ok(())
}).await;
// convert DsqlError → anyhow::Error here
result.map_err(|e| anyhow::anyhow!(e))?;

Share this post

Shinya Tahara

Shinya Tahara

Solutions Architect @ AWS

I'm a Solutions Architect at AWS, providing technical guidance primarily to financial industry customers. I share learnings about cloud architecture and AI/ML on this site.The views and opinions expressed on this site are my own and do not represent the official positions of my employer.