1use std::{error::Error, fmt};
2
3use sea_orm::{ConnectionTrait, DbErr};
4
5#[derive(Debug)]
7pub enum Lock<C>
8where
9 C: ConnectionTrait + fmt::Debug,
10{
11 DbErr(String, C, Option<DbErr>),
13 Failed(String, C),
15}
16
17impl<C> fmt::Display for Lock<C>
18where
19 C: ConnectionTrait + fmt::Debug,
20{
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Lock::DbErr(key, _, Some(e)) => {
24 write!(f, "error while locking for key {key}: {e}")
25 }
26 Lock::DbErr(key, _, None) => {
27 write!(f, "error while locking for key {key}: unknown error")
28 }
29 Lock::Failed(key, _) => write!(f, "lock failed for key {key}"),
30 }
31 }
32}
33
34impl<C> Error for Lock<C> where C: ConnectionTrait + fmt::Debug {}
35
36#[derive(Debug)]
38pub enum Unlock<C>
39where
40 C: ConnectionTrait + fmt::Debug,
41{
42 DbErr(super::Lock<C>, Option<DbErr>),
44 Failed(super::Lock<C>),
46}
47
48impl<C> fmt::Display for Unlock<C>
49where
50 C: ConnectionTrait + fmt::Debug,
51{
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 match self {
54 Unlock::DbErr(lock, Some(e)) => {
55 write!(f, "error while unlocking for key {}: {}", lock.get_key(), e)
56 }
57 Unlock::DbErr(lock, None) => {
58 write!(
59 f,
60 "error while unlocking for key {}: unknown error",
61 lock.get_key()
62 )
63 }
64 Unlock::Failed(lock) => write!(f, "unlock failed for key {}", lock.get_key()),
65 }
66 }
67}
68
69impl<C> Error for Unlock<C> where C: ConnectionTrait + fmt::Debug {}