testkit_postgres/
error.rs1use std::fmt::Debug;
2use thiserror::Error;
3
4#[derive(Error, Debug, Clone)]
6pub enum PostgresError {
7 #[error("Connection error: {0}")]
9 ConnectionError(String),
10
11 #[error("Query execution error: {0}")]
13 QueryError(String),
14
15 #[error("Database creation error: {0}")]
17 DatabaseCreationError(String),
18
19 #[error("Database drop error: {0}")]
21 DatabaseDropError(String),
22
23 #[error("Transaction error: {0}")]
25 TransactionError(String),
26
27 #[error("Configuration error: {0}")]
29 ConfigError(String),
30
31 #[error("Pool creation error: {0}")]
33 PoolCreationError(String),
34
35 #[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#[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}