From 5e3e813900ec74591ec8711e4673148c617c2993 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 17 Oct 2021 23:25:22 +0300 Subject: [PATCH] doc: add for errors --- src/error.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 0d706b7..6653c84 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,14 +1,26 @@ use std::error; use std::fmt; +/// A helper type for any result with persistence error. +/// +/// Use this type in your repository or in something else that implements methods for your persistence. pub type Result = std::result::Result; +/// All supported kinds of persistence error #[derive(Debug)] pub enum PersistenceError { + /// Returns if we cannot get a connection from pool. GetConnection, + /// Returns if we cannot upgrade connection to transaction. + #[cfg(feature = "nightly")] UpgradeToTransaction, + /// Returns if we cannot commit transaction. + #[cfg(feature = "nightly")] CommitTransaction, + /// Returns if we cannot rolls back transaction. + #[cfg(feature = "nightly")] RollbackTransaction, + /// Rest database errors contains here. DbError(Box), } @@ -16,11 +28,16 @@ impl fmt::Display for PersistenceError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { PersistenceError::GetConnection => f.write_str("Cannot get connection"), + #[cfg(feature = "nightly")] PersistenceError::UpgradeToTransaction => { f.write_str("Cannot upgrade connection to transaction") } - PersistenceError::CommitTransaction => f.write_str("Cannot commit transaction"), - PersistenceError::RollbackTransaction => f.write_str("Cannot rollback transaction"), + #[cfg(feature = "nightly")] + PersistenceError::CommitTransaction => { + f.write_str("Cannot commit changes of transaction") + } + #[cfg(feature = "nightly")] + PersistenceError::RollbackTransaction => f.write_str("Cannot rolls transaction back"), PersistenceError::DbError(err) => write!(f, "DbError: {}", err), } }