Skip to main content

aurora_dsql_sqlx_connector/
error.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use thiserror::Error;
5
6#[cfg(feature = "occ")]
7use crate::occ_retry::OCCType;
8
9pub type Result<T> = std::result::Result<T, DsqlError>;
10
11#[derive(Error, Debug)]
12#[non_exhaustive]
13pub enum DsqlError {
14    #[error("configuration error: {0}")]
15    ConfigError(#[source] Box<dyn std::error::Error + Send + Sync>),
16
17    #[error("token error: {0}")]
18    TokenError(#[source] Box<dyn std::error::Error + Send + Sync>),
19
20    #[error("connection error: {0}")]
21    ConnectionError(#[source] sqlx::Error),
22
23    #[error("database error: {0}")]
24    DatabaseError(#[source] sqlx::Error),
25
26    #[cfg(feature = "occ")]
27    #[error("OCC retry exhausted after {attempts} attempts (type: {occ_type:?}): {source}")]
28    OCCRetryExhausted {
29        attempts: u32,
30        occ_type: OCCType,
31        #[source]
32        source: Box<DsqlError>,
33    },
34}
35
36#[cfg(feature = "occ")]
37impl From<crate::occ_retry::OCCRetryConfigBuilderError> for DsqlError {
38    fn from(err: crate::occ_retry::OCCRetryConfigBuilderError) -> Self {
39        DsqlError::ConfigError(Box::new(err))
40    }
41}