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.
expected `sqlx::Error`, found `anyhow::Error`Looking at the retry_on_occ signature, the closure's Future must return Result<T, sqlx::Error>.
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 asDsqlError::OCCRetryExhaustedon retry exhaustion)
Inside the closure, just propagate sqlx::Error with ?. Convert to anyhow outside retry_on_occ.
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))?;