Skip to main content

pg_wired/
error.rs

1//! Error type for the `pg-wired` crate.
2
3use crate::protocol::types::PgError;
4
5/// Top-level error type returned by `pg-wired`.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum PgWireError {
9    /// Local I/O failure (TCP, TLS, or read/write on the socket).
10    #[error("I/O error: {0}")]
11    Io(#[from] std::io::Error),
12
13    /// PostgreSQL returned an `ErrorResponse` message. Inspect the wrapped
14    /// [`PgError`] for SQLSTATE code and detail fields.
15    #[error("PostgreSQL error: {}: {}", .0.code, .0.message)]
16    Pg(PgError),
17
18    /// Server response could not be parsed as a valid v3 protocol message,
19    /// or the message arrived out of order for the current connection state.
20    #[error("Protocol error: {0}")]
21    Protocol(String),
22
23    /// The connection was closed mid-operation (peer disconnect, EOF on read,
24    /// reader/writer task died).
25    #[error("Connection closed")]
26    ConnectionClosed,
27}