toasty_core/error/
driver_operation_failed.rs

1use super::Error;
2
3/// Error when a database driver operation fails.
4///
5/// This wraps errors from underlying database driver libraries when operations fail:
6/// - Connection errors (rusqlite, tokio-postgres, AWS SDK)
7/// - Query execution errors
8/// - Transaction operation errors (BEGIN, COMMIT, ROLLBACK)
9/// - Schema operation errors (CREATE TABLE, CREATE INDEX)
10/// - URL parsing errors for connection strings
11#[derive(Debug)]
12pub(super) struct DriverOperationFailed {
13    pub(super) inner: Box<dyn std::error::Error + Send + Sync>,
14}
15
16impl std::error::Error for DriverOperationFailed {
17    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
18        Some(self.inner.as_ref())
19    }
20}
21
22impl core::fmt::Display for DriverOperationFailed {
23    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
24        // Display the error and walk its source chain
25        core::fmt::Display::fmt(&self.inner, f)?;
26        let mut source = self.inner.source();
27        while let Some(err) = source {
28            write!(f, ": {}", err)?;
29            source = err.source();
30        }
31        Ok(())
32    }
33}
34
35impl Error {
36    /// Creates an error from a driver operation failure.
37    ///
38    /// This is the preferred way to convert driver-specific errors (rusqlite, tokio-postgres,
39    /// mysql_async, AWS SDK errors, etc.) into toasty errors.
40    pub fn driver_operation_failed(err: impl std::error::Error + Send + Sync + 'static) -> Error {
41        Error::from(super::ErrorKind::DriverOperationFailed(
42            DriverOperationFailed {
43                inner: Box::new(err),
44            },
45        ))
46    }
47
48    /// Returns `true` if this error is a driver operation failure.
49    pub fn is_driver_operation_failed(&self) -> bool {
50        matches!(self.kind(), super::ErrorKind::DriverOperationFailed(_))
51    }
52}