Source: https://gres.monicz.dev/api/errors/

# Errors

[Errors and retries](https://gres.monicz.dev/guide/errors/) shows the hierarchy and how to act on it.

Driver failures, distinct from cancellation of the calling asyncio task.

## Error

Base class of every error Gres raises.

`dispatch_state`, `connection_invalidated` and `transaction_outcome` say what is
known about the failed call's effect.

### phase `property`

```python
phase: Literal['bind', 'describe', 'encode', 'decode'] | None
```

Local step that failed, or `None` for server and connection failures.

`'bind'` is placeholder lookup, `'describe'` type resolution, `'encode'`
parameter conversion and `'decode'` result conversion.

### parameter\_position `property`

```python
parameter_position: int | None
```

One-based parameter position in the caller's SQL, when known.

### parameter\_name `property`

```python
parameter_name: str | None
```

Named SQL placeholder without its dollar prefix.

### column\_index `property`

```python
column_index: int | None
```

Zero-based result column for a local conversion failure.

### column\_name `property`

```python
column_name: str | None
```

Result column label, or the column reported by PostgreSQL.

### postgres\_type `property`

```python
postgres_type: str | None
```

Diagnostic name of the expected PostgreSQL type, when known.

### python\_type `property`

```python
python_type: type[object] | None
```

Type of the rejected Python input, without retaining the value.

### dispatch\_state `property`

```python
dispatch_state: Literal['not_sent', 'possibly_sent'] | None
```

Whether the statement may have reached PostgreSQL.

`'not_sent'` if it never did, `'possibly_sent'` if it may have executed, and
`None` if the call was refused before it started.

### connection\_invalidated `property`

```python
connection_invalidated: bool | None
```

Whether this failure discarded the PostgreSQL session.

A pool replaces the session; a `Connection` is closed.

### transaction\_outcome `property`

```python
transaction_outcome: (
    Literal['committed', 'rolled_back', 'released', 'unknown'] | None
)
```

How a managed transaction ended when its commit, rollback or release failed.

`None` for other errors.

## ConfigurationError

An invalid or unsupported connection setting.

## InterfaceError

The resource cannot accept this operation.

## NotificationOverflowError

The notification queue filled. Reconcile application state and start a new listener.

## PoolBusyError

Physical capacity is occupied and the pool cannot admit another waiter.

## ServerError

PostgreSQL rejected the operation; `sqlstate` identifies the condition.

### sqlstate `property`

```python
sqlstate: str | None
```

Five-character PostgreSQL condition code.

### severity `property`

```python
severity: str | None
```

Severity reported by PostgreSQL.

### message `property`

```python
message: str | None
```

Primary server diagnostic message.

### detail `property`

```python
detail: str | None
```

Additional detail supplied by PostgreSQL.

### hint `property`

```python
hint: str | None
```

Corrective action suggested by PostgreSQL.

### position `property`

```python
position: int | None
```

One-based character position in the statement reported by PostgreSQL.

### schema\_name `property`

```python
schema_name: str | None
```

Schema identified by the server.

### table\_name `property`

```python
table_name: str | None
```

Table identified by the server.

### datatype\_name `property`

```python
datatype_name: str | None
```

Data type identified by the server.

### constraint\_name `property`

```python
constraint_name: str | None
```

Constraint identified by the server.

## IntegrityError

PostgreSQL rejected a change that would violate an integrity constraint.

## DataError

PostgreSQL could not process the supplied data.

## ProgrammingError

PostgreSQL rejected the SQL syntax, object reference or access rule.

## OperationalError

PostgreSQL reported an operational failure, such as a serialization conflict.

## NotSupportedError

PostgreSQL does not support the requested feature.

## InternalError

PostgreSQL reported an internal error or invalid transaction state.

## UniqueViolation

A unique constraint rejected a duplicate key (`23505`).

## ForeignKeyViolation

A foreign key constraint would be violated (`23503`).

## NotNullViolation

A `NULL` was rejected by a `NOT NULL` constraint (`23502`).

## CheckViolation

A `CHECK` constraint rejected the row (`23514`).

## ExclusionViolation

An exclusion constraint rejected a conflicting row (`23P01`).

## SerializationFailure

PostgreSQL could not serialize the transaction (`40001`).

## DeadlockDetected

PostgreSQL aborted the operation to resolve a deadlock (`40P01`).

## LockNotAvailable

A `NOWAIT` lock request or `lock_timeout` could not obtain the lock (`55P03`).

## QueryCanceled

PostgreSQL canceled the statement, for example at `statement_timeout` (`57014`).

## ReadOnlySqlTransaction

A write was attempted in a read-only transaction or on a standby (`25006`).

## ConnectionError

The physical session could not be established or retained.

## TransactionLostError

The session can no longer continue the managed transaction.

## CommitOutcomeUnknownError

`COMMIT` may have reached PostgreSQL, but no conclusive response was observed.

## ProtocolError

A backend message did not fit the current protocol exchange.

## QueryShapeError

The statement requested a transfer the selected method cannot supply.

## DecodingError

A decoded SQL value cannot be represented by the chosen result.

## EncodingError

A parameter cannot be encoded as the destination PostgreSQL type.

## UnsupportedTypeError

No installed codec can supply the requested SQL type.

## CardinalityError

A completed statement returned the wrong number of rows.

## TimeoutError

```python
TimeoutError(message: str, *, sent: bool, invalidated: bool = False)
```

The driver's monotonic budget expired, not an external task cancellation.
