Documentation

Errors & troubleshooting

Error shape, codes, retry behavior, and common issues.

Result shape

Queries return { data, error, count, status, statusText }. Query/database errors do not throw by default; check error or use .throwOnError().

const { data, error, status } = await db.from('users').select('*')
if (error) {
  console.error(error.code, error.message, error.details, error.hint)
}

error is PostgREST-compatible for builder queries: { message, details, hint, code } (or null on success). details/hint are null when absent. For builder results, status and statusText live on the envelope.

Raw SQL helpers (db.sql / db.unsafe()) return a RawResult whose error is a classified error object and may also include kind and status.

Error codes

CodeMeaning
PGRST100Parse / invalid request (including missing embed for dotted filter).
PGRST106Schema not exposed / not in allowlist.
PGRST116Cardinality mismatch (single()/maybeSingle()).
PGRST200/201Relationship resolution errors.
PGRST202/203Function/RPC resolution errors.
PGRST204Column not found / schema-cache related column error.
PGFLUENT_INVALID_QUERYInvalid query shape/value rejected by pg-fluent.
PGFLUENT_UNFILTERED_MUTATIONUnfiltered UPDATE/DELETE blocked client-side.
PGFLUENT_TIMEOUTStatement timeout.
PGFLUENT_ABORTEDRequest aborted.
PGFLUENT_CONNECTIONConnection/connectivity failure.
PGFLUENT_POOL_EXHAUSTEDPool could not provide a connection.
PGFLUENT_CLOSEDClient/pool closed.
PGFLUENT_NOT_IMPLEMENTEDUnsupported feature/path.
Postgres SQLSTATEDatabase errors use the PostgreSQL SQLSTATE (for example 23505 unique violation).

Error kinds

pg-fluent uses classified errors internally. PgFluentError.kind covers pg-fluent runtime/configuration failures (such as validation, connection, timeout, aborted, internal). PostgREST-shaped request errors and databaseError() classifications can also surface kinds like parse, method, accept, range, notfound, multiple, unauthorized, and database. Builder wire error objects keep the PostgREST shape (message/details/hint/code) and do not include kind.

Retries

Only idempotent work (reads/HEAD/non-volatile RPC) is retried on transient connection failures, with exponential backoff + jitter. Default: { max: 2, backoffMs: 50, idempotent: true }. Writes are never retried outside an explicit transaction retry.

Transaction retries can be enabled with retry (count) and apply to serialization failures/deadlocks (40001/40P01). The callback must be idempotent.

Troubleshooting

No rows / cardinality errors

data: [] (or null for maybeSingle()) with no error means the query succeeded but matched no rows. PGRST116 means a single-object response was requested but zero or multiple rows were returned.

Unfiltered mutation blocked

PGFLUENT_UNFILTERED_MUTATION means an UPDATE/DELETE had no filters. Add a filter, or opt in explicitly with .allowUnfiltered() / allowUnfilteredMutations: true.

Timeouts / aborts

PGFLUENT_TIMEOUT indicates a statement timeout. PGFLUENT_ABORTED indicates the request signal was aborted. For per-request control use .timeout(ms) / .abortSignal(signal).

Connection / pool errors

PGFLUENT_CONNECTION / PGFLUENT_POOL_EXHAUSTED indicate pool or connectivity issues. Check the connection string, pool limits, and database availability. Streaming and COPY failures destroy affected pooled connections so poisoned connections are not reused.

LISTEN/NOTIFY

LISTEN requires a direct/session connection; transaction-mode poolers (e.g. PgBouncer transaction pooling) are not compatible. Notifications missed during disconnect are lost; use onReconnect to re-sync. listen() is unavailable inside transaction clients.

Schema cache / type generation

If schema changes are not reflected, call await db.refreshSchema(). For NOTIFY-driven refresh, see docs/schema-notify.sql in the repository. pg-fluent gen-types requires a reachable database and never prints the connection string.

RLS / auth

pg-fluent runs SQL as the configured database role. Supabase RLS policies for anon/authenticated JWT contexts are not emulated automatically. Use a least-privilege role and do not expose the client to untrusted input. See Security & RLS.