Module errors

June 1, 2026 · View on GitHub

⤌ Back

Module errors

Exception hierarchy for the postgres client library. All postgres exceptions extend PostgresError which itself extends the built-in Exception, so callers can catch the entire family with a single catch block while still being able to discriminate finer-grained types.

catch {
  conn.query('bad sql')
} as e
if isinstance(e, PostgresError) {
  echo 'postgres error: ' + e.message
}

Classes

class PostgresError < Exception

Base class for all errors raised by the postgres client library.

Properties

  • code

  • severity

  • detail

  • hint

  • position

Methods

  • PostgresError(message, fields) (Constructor)

    Creates a PostgresError.

    Parameters

    • string message The primary error description.

    • dict fields Optional dict of additional server error fields.

class ConnectionError < PostgresError

Raised when a network or socket-level failure prevents communication with the PostgreSQL server (connection refused, broken pipe, timeout, etc.).

class QueryError < PostgresError

Raised when the server returns an error response to a query or command. The code field will contain the SQLSTATE code from the server.

class AuthenticationError < PostgresError

Raised when authentication with the PostgreSQL server fails, including wrong credentials, unsupported auth method, or SASL negotiation failure.

class ProtocolError < PostgresError

Raised when the client receives an unexpected or malformed message from the server, indicating a protocol-level disagreement.

class ClosedError < PostgresError

Raised when an operation is attempted on a closed connection or cursor.

class PoolExhaustedError < PostgresError

Raised when a connection pool is exhausted and max connections are all in use and the caller did not opt into waiting.