qail_pg/protocol/
error.rs

1//! Encoding errors for PostgreSQL wire protocol.
2//!
3//! Shared by `PgEncoder` and `AstEncoder`.
4
5use std::fmt;
6
7/// Errors that can occur during wire protocol encoding.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum EncodeError {
10    /// A string value contains a literal NULL byte (0x00).
11    NullByte,
12    /// Too many parameters for the protocol (limit is i16::MAX = 32767).
13    TooManyParameters(usize),
14}
15
16impl fmt::Display for EncodeError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            EncodeError::NullByte => {
20                write!(f, "Value contains NULL byte (0x00) which is invalid in PostgreSQL")
21            }
22            EncodeError::TooManyParameters(count) => {
23                write!(f, "Too many parameters: {} (Limit is 32767)", count)
24            }
25        }
26    }
27}
28
29impl std::error::Error for EncodeError {}