qail_pg/protocol/
error.rs1use std::fmt;
6
7use qail_core::ast::Action;
8
9#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum EncodeError {
12 NullByte,
14 TooManyParameters(usize),
16 MessageTooLarge(usize),
18 InvalidMaxRows(i32),
20 UnsupportedAction(Action),
22 InvalidAst(String),
24 UnsafeExpression(String),
26}
27
28impl fmt::Display for EncodeError {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 EncodeError::NullByte => {
32 write!(
33 f,
34 "Value contains NULL byte (0x00) which is invalid in PostgreSQL"
35 )
36 }
37 EncodeError::TooManyParameters(count) => {
38 write!(f, "Too many parameters: {} (Limit is 32767)", count)
39 }
40 EncodeError::MessageTooLarge(size) => {
41 write!(
42 f,
43 "Message too large: {} bytes (Limit is {})",
44 size,
45 i32::MAX
46 )
47 }
48 EncodeError::InvalidMaxRows(v) => {
49 write!(f, "Invalid Execute max_rows: {} (must be >= 0)", v)
50 }
51 EncodeError::UnsupportedAction(action) => {
52 write!(f, "Unsupported action {:?} in AST-native encoder", action)
53 }
54 EncodeError::InvalidAst(message) => write!(f, "Invalid AST: {}", message),
55 EncodeError::UnsafeExpression(expr) => {
56 write!(f, "Unsafe expression rejected: {}", expr)
57 }
58 }
59 }
60}
61
62impl std::error::Error for EncodeError {}