Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions async_postgres/pg_connection.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import std/[tables, sets, strutils, uri, deques, options, lists]
when defined(posix):
import std/posix

import async_backend, pg_protocol, pg_auth, pg_types
import async_backend, pg_errors, pg_protocol, pg_auth, pg_types

when hasChronos:
import chronos/streams/tlsstream
Expand All @@ -13,7 +13,7 @@ elif hasAsyncDispatch:
when defined(ssl):
import std/[net, openssl, tempfiles, os]

export PgError
export pg_errors

# TCP keepalive socket options (not exported by posix module)
when defined(linux):
Expand All @@ -33,23 +33,6 @@ else:
.}

type
PgConnectionError* = object of PgError
## Connection failures, disconnections, SSL/auth errors.

PgQueryError* = object of PgError
## SQL execution errors from the server (ErrorResponse).
sqlState*: string ## 5-char SQLSTATE code (e.g. "42P01"), empty if unavailable.
severity*: string ## e.g. "ERROR", "FATAL"
detail*: string ## DETAIL field, empty if not present.
hint*: string ## HINT field, empty if not present.

PgTimeoutError* = object of PgError ## Operation timed out.

PgPoolError* = object of PgError ## Pool exhaustion, pool closed, or acquire timeout.

PgNotifyOverflowError* = object of PgError
dropped*: int ## Number of notifications dropped due to queue overflow

PgConnState* = enum
## Connection lifecycle state.
csConnecting
Expand Down
35 changes: 35 additions & 0 deletions async_postgres/pg_errors.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Exception hierarchy.
##
## All library-raised exceptions derive from ``PgError`` so callers can catch
## every pg-specific failure with a single ``except PgError`` clause. ``ProtocolError``
## is a subtype of ``PgConnectionError`` because a protocol-level violation
## desynchronises the wire stream — the only viable recovery is to tear down
## and re-establish the connection.

type
PgError* = object of CatchableError
## General PostgreSQL error. Base type for all pg-specific errors.

PgTypeError* = object of PgError
## Raised when a PostgreSQL value cannot be converted to the requested Nim type.

PgConnectionError* = object of PgError
## Connection failures, disconnections, SSL/auth errors.

ProtocolError* = object of PgConnectionError
## Raised on PostgreSQL wire protocol violations. The connection stream is
## desynchronised after this error and must be torn down.

PgQueryError* = object of PgError
## SQL execution errors from the server (ErrorResponse).
sqlState*: string ## 5-char SQLSTATE code (e.g. "42P01"), empty if unavailable.
severity*: string ## e.g. "ERROR", "FATAL"
detail*: string ## DETAIL field, empty if not present.
hint*: string ## HINT field, empty if not present.

PgTimeoutError* = object of PgError ## Operation timed out.

PgPoolError* = object of PgError ## Pool exhaustion, pool closed, or acquire timeout.

PgNotifyOverflowError* = object of PgError
dropped*: int ## Number of notifications dropped due to queue overflow
6 changes: 2 additions & 4 deletions async_postgres/pg_protocol.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import std/[options, tables]

import pg_bytes
import pg_bytes, pg_errors
export pg_errors

type
ProtocolError* = object of CatchableError
## Raised on PostgreSQL wire protocol violations.

FrontendMessageKind* = enum
## Message types sent from client to server.
fmkStartup
Expand Down
9 changes: 3 additions & 6 deletions async_postgres/pg_types/core.nim
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import std/[hashes, options, sequtils, strutils, tables, net]

type
PgError* = object of CatchableError
## General PostgreSQL error. Base type for all pg-specific errors.

PgTypeError* = object of PgError
## Raised when a PostgreSQL value cannot be converted to the requested Nim type.
import ../pg_errors
export pg_errors

type
PgUuid* = distinct string
## UUID value stored as its string representation (e.g. "550e8400-e29b-41d4-a716-446655440000").

Expand Down