heliosdb_proxy/backend/error.rs
1//! Backend client error types.
2
3use thiserror::Error;
4
5/// Errors produced while acting as a PostgreSQL client.
6#[derive(Debug, Error)]
7pub enum BackendError {
8 /// I/O on the underlying TCP or TLS stream failed.
9 #[error("backend I/O error: {0}")]
10 Io(#[from] std::io::Error),
11
12 /// The backend closed the connection before the expected reply
13 /// arrived (e.g. TCP RST, idle timeout, server shutdown).
14 #[error("backend closed connection unexpectedly")]
15 Closed,
16
17 /// A protocol-level violation: unexpected message type, malformed
18 /// payload, or truncated frame.
19 #[error("protocol violation: {0}")]
20 Protocol(String),
21
22 /// The backend returned an `ErrorResponse` (tag `E`). The string is
23 /// the `M` (Message) field, which is always present.
24 #[error("backend error: {0}")]
25 BackendError(String),
26
27 /// Authentication did not complete successfully — wrong password,
28 /// unsupported SASL mechanism, or SCRAM server verifier mismatch.
29 #[error("authentication failed: {0}")]
30 Auth(String),
31
32 /// TLS handshake failed. String carries the rustls diagnostic.
33 #[error("TLS error: {0}")]
34 Tls(String),
35
36 /// Unsupported type OID in a result column — the proxy only knows
37 /// how to decode a fixed set of common OIDs.
38 #[error("unsupported type OID: {0}")]
39 UnsupportedType(u32),
40
41 /// Value parsing (text-format) failed — e.g. malformed int, bad
42 /// boolean string, invalid timestamp.
43 #[error("value parse error: column {column}: {reason}")]
44 ParseValue { column: String, reason: String },
45}
46
47pub type BackendResult<T> = std::result::Result<T, BackendError>;