1use std::fmt;
4
5pub type CheckResult<T> = Result<T, CheckError>;
7
8#[derive(Debug)]
10pub enum CheckError {
11 Database(tokio_postgres::Error),
13 Validation(String),
15 Serialization(String),
17 Decode { column: String, message: String },
19 Other(String),
21}
22
23impl fmt::Display for CheckError {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 CheckError::Database(e) => write!(f, "Database error: {e}"),
27 CheckError::Validation(msg) => write!(f, "Validation error: {msg}"),
28 CheckError::Serialization(msg) => write!(f, "Serialization error: {msg}"),
29 CheckError::Decode { column, message } => {
30 write!(f, "Decode error for column '{column}': {message}")
31 }
32 CheckError::Other(msg) => write!(f, "{msg}"),
33 }
34 }
35}
36
37impl std::error::Error for CheckError {
38 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
39 match self {
40 CheckError::Database(e) => Some(e),
41 _ => None,
42 }
43 }
44}
45
46impl From<tokio_postgres::Error> for CheckError {
47 fn from(e: tokio_postgres::Error) -> Self {
48 CheckError::Database(e)
49 }
50}
51
52impl CheckError {
53 pub fn decode(column: impl Into<String>, message: impl Into<String>) -> Self {
55 CheckError::Decode {
56 column: column.into(),
57 message: message.into(),
58 }
59 }
60}