testkit_mysql/
error.rs

1use thiserror::Error;
2
3/// MySQL-specific errors for the testkit
4#[derive(Error, Debug, Clone)]
5pub enum MySqlError {
6    /// Error with the configuration
7    #[error("Configuration error: {0}")]
8    ConfigError(String),
9
10    /// Error connecting to the database
11    #[error("Connection error: {0}")]
12    ConnectionError(String),
13
14    /// Error creating a database
15    #[error("Database creation error: {0}")]
16    DatabaseCreationError(String),
17
18    /// Error dropping a database
19    #[error("Database drop error: {0}")]
20    DatabaseDropError(String),
21
22    /// Error executing a query
23    #[error("Query execution error: {0}")]
24    QueryExecutionError(String),
25
26    /// Error with transactions
27    #[error("Transaction error: {0}")]
28    TransactionError(String),
29
30    /// Generic error
31    #[error("MySQL error: {0}")]
32    Generic(String),
33}
34
35impl From<String> for MySqlError {
36    fn from(s: String) -> Self {
37        MySqlError::Generic(s)
38    }
39}
40
41impl From<&str> for MySqlError {
42    fn from(s: &str) -> Self {
43        MySqlError::Generic(s.to_string())
44    }
45}
46
47#[cfg(feature = "with-mysql-async")]
48impl From<mysql_async::Error> for MySqlError {
49    fn from(error: mysql_async::Error) -> Self {
50        MySqlError::Generic(error.to_string())
51    }
52}
53
54#[cfg(feature = "with-sqlx")]
55impl From<sqlx::Error> for MySqlError {
56    fn from(error: sqlx::Error) -> Self {
57        MySqlError::Generic(error.to_string())
58    }
59}