testkit_postgres/
error.rs

1use std::fmt::Debug;
2use thiserror::Error;
3
4/// Error type for PostgreSQL operations
5#[derive(Error, Debug, Clone)]
6pub enum PostgresError {
7    /// Error connecting to the database
8    #[error("Connection error: {0}")]
9    ConnectionError(String),
10
11    /// Error executing a query
12    #[error("Query execution error: {0}")]
13    QueryError(String),
14
15    /// Error creating a database
16    #[error("Database creation error: {0}")]
17    DatabaseCreationError(String),
18
19    /// Error dropping a database
20    #[error("Database drop error: {0}")]
21    DatabaseDropError(String),
22
23    /// Error during transaction operations
24    #[error("Transaction error: {0}")]
25    TransactionError(String),
26
27    /// Error from configuration
28    #[error("Configuration error: {0}")]
29    ConfigError(String),
30
31    /// Error creating a pool
32    #[error("Pool creation error: {0}")]
33    PoolCreationError(String),
34
35    /// Any other error
36    #[error("Other error: {0}")]
37    Other(String),
38}
39
40impl From<String> for PostgresError {
41    fn from(s: String) -> Self {
42        Self::Other(s)
43    }
44}
45
46impl From<&str> for PostgresError {
47    fn from(s: &str) -> Self {
48        Self::Other(s.to_string())
49    }
50}
51
52// Feature-specific error conversions
53#[cfg(feature = "with-tokio-postgres")]
54impl From<tokio_postgres::Error> for PostgresError {
55    fn from(err: tokio_postgres::Error) -> Self {
56        Self::QueryError(err.to_string())
57    }
58}
59
60#[cfg(feature = "with-sqlx")]
61impl From<sqlx::Error> for PostgresError {
62    fn from(err: sqlx::Error) -> Self {
63        Self::QueryError(err.to_string())
64    }
65}