1use postgresql_protocol::{DbError, error::Error as ProtocolError};
4
5#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9 #[error("{0}")]
13 Server(Box<DbError>),
14
15 #[error(transparent)]
17 Protocol(ProtocolError),
18
19 #[error("I/O error: {0}")]
21 Io(#[from] std::io::Error),
22
23 #[error("TLS error: {0}")]
25 Tls(#[from] rustls::Error),
26
27 #[error("configuration error: {0}")]
29 Config(String),
30
31 #[error("connection closed")]
33 Closed,
34
35 #[error("connection failed: {0}")]
40 ConnectionFailed(String),
41
42 #[error("connection pool timed out")]
44 PoolTimedOut,
45
46 #[error("connection pool closed")]
48 PoolClosed,
49
50 #[error("row not found")]
52 RowNotFound,
53
54 #[error("column not found: {0}")]
56 ColumnNotFound(String),
57
58 #[error("unexpected NULL in column {0}")]
60 UnexpectedNull(String),
61
62 #[error("decode error: {0}")]
64 Decode(String),
65
66 #[error("encode error: {0}")]
68 Encode(String),
69
70 #[error("time error: {0}")]
72 Time(#[from] time::Error),
73
74 #[error("uuid error: {0}")]
76 Uuid(#[from] uuid::Error),
77
78 #[error("json error: {0}")]
80 Json(#[from] serde_json::Error),
81
82 #[error("ipnetwork error: {0}")]
84 IpNetwork(#[from] ipnetwork::IpNetworkError),
85
86 #[error("invalid UTF-8: {0}")]
88 Utf8(#[from] std::str::Utf8Error),
89}
90
91impl From<DbError> for Error {
92 fn from(err: DbError) -> Self {
93 Error::Server(Box::new(err))
94 }
95}
96
97impl From<ProtocolError> for Error {
98 fn from(err: ProtocolError) -> Self {
99 match err {
100 ProtocolError::Server(db) => Error::Server(db),
101 other => Error::Protocol(other),
102 }
103 }
104}