1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
use thiserror::Error; #[derive(Error, Debug)] pub enum C3p0Error { #[error("InternalError: [{cause}]")] InternalError { cause: String }, #[error("DbError. DB: {db}. DB specific error code: [{code:?}]. Msg: {cause}")] DbError { db: &'static str, cause: String, code: Option<String>, }, #[error("RowMapperError: [{cause}]")] RowMapperError { cause: String }, #[error("OptimisticLockError: [{message}]")] OptimisticLockError { message: String }, #[error("JsonProcessingError: [{cause}]")] JsonProcessingError { cause: serde_json::error::Error }, #[error("IteratorError: [{message}]")] IteratorError { message: String }, #[error("PoolError: pool [{pool}] for [{db}] returned error: [{cause}]")] PoolError { db: &'static str, pool: &'static str, cause: String, }, #[error("ResultNotFoundError: Expected one result but found zero.")] ResultNotFoundError, #[error("TransactionError: [{cause}]")] TransactionError { cause: Box<dyn std::error::Error + Send + Sync>, }, #[error("CorruptedDbMigrationState: [{message}]")] CorruptedDbMigrationState { message: String }, #[error("AlteredMigrationSql: [{message}]")] AlteredMigrationSql { message: String }, #[error("WrongMigrationSet: [{message}]")] WrongMigrationSet { message: String }, #[error("FileSystemError: [{message}]")] FileSystemError { message: String }, #[error("MigrationError: [{message}]. Cause: [{cause}]")] MigrationError { message: String, cause: Box<C3p0Error>, }, } impl From<serde_json::error::Error> for C3p0Error { fn from(cause: serde_json::error::Error) -> Self { C3p0Error::JsonProcessingError { cause } } } #[cfg(test)] mod test { use super::*; use static_assertions::*; #[test] fn error_should_be_send_and_sync() { assert_impl_all!(C3p0Error: Send, Sync); } }