| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasql.Errors
Description
Explicit error types for all Hasql operations.
This module provides access to all error types used throughout Hasql:
AcquireError- errors that occur when establishing a database connectionUseError- errors returned when using a connectionSessionError- recoverable errors that occur during session execution
The module follows Hasql's philosophy of explicit error handling, where all errors are represented as values rather than exceptions.
Synopsis
- class IsError a where
- toDetailedText :: IsError e => e -> Text
- data AcquireError
- data UseError
- data SessionError
- data StatementError
- data RowError
- data CellError
- data ServerError = ServerError Text Text (Maybe Text) (Maybe Text) (Maybe Int)
Error class
A class for types that can be treated as errors.
This is a rendering interface: it turns an error value into a human-readable message, a list of dynamic details, and - where the error carries one - the server's SQLSTATE. It deliberately does not offer a retryability verdict. Whether an operation is worth retrying depends on the caller's retry policy, the transaction it sits inside, and the SQLSTATE where one is available - not on a boolean this class hands out. Hasql declines to own that decision, so the omission here is not an oversight.
Methods
Convert the error to a human-readable message with no dynamic details.
toDetails :: a -> [(Text, Text)] #
Convert the error to a list of key-value pairs of dynamic details.
toSqlState :: a -> Maybe Text #
The SQLSTATE the server reported, if this error carries one at all.
Lets you branch on a PostgreSQL error code without knowing which constructors of which error type the server error is nested under. For the code vocabulary see https://www.postgresql.org/docs/current/errcodes-appendix.html.
Nothing means the error carries no server code: a connection failure, a
decoding failure, a driver bug. It never means "the operation succeeded".
The default implementation returns Nothing, which is correct only for
error types that can never carry a server error. A type that wraps another
error type MUST override it and delegate to the wrapped value, otherwise it
silently reports Nothing for codes it does in fact carry.
Instances
| IsError AcquireError # | |
Defined in Hasql.Errors Methods toMessage :: AcquireError -> Text # toDetails :: AcquireError -> [(Text, Text)] # toSqlState :: AcquireError -> Maybe Text # | |
| IsError CellError # | |
| IsError RowError # | |
| IsError ServerError # | |
Defined in Hasql.Errors Methods toMessage :: ServerError -> Text # toDetails :: ServerError -> [(Text, Text)] # toSqlState :: ServerError -> Maybe Text # | |
| IsError SessionError # | |
Defined in Hasql.Errors Methods toMessage :: SessionError -> Text # toDetails :: SessionError -> [(Text, Text)] # toSqlState :: SessionError -> Maybe Text # | |
| IsError StatementError # | |
Defined in Hasql.Errors Methods toMessage :: StatementError -> Text # toDetails :: StatementError -> [(Text, Text)] # toSqlState :: StatementError -> Maybe Text # | |
| IsError UseError # | |
toDetailedText :: IsError e => e -> Text #
Convert the error to a multiline detailed human-readable text representation containing all details.
Acquire errors
data AcquireError #
Error that occurs when attempting to establish a database connection.
These errors can occur when calling acquire, which runs
three stages in sequence: it establishes a connection, checks the server
version, and initializes session settings. A constructor is named for its
stage, then its case: a bare stage name means nothing further is known at
that stage, and a stage with only one case needs no prefix. Reaching a
stage is therefore a claim about everything before it - a failure at
initialization means the connection was established and the server
version was accepted.
Every constructor here publishes only what the driver actually observed.
libpq produces no structured signal for a failure while connecting - no
ServerError is available - so ConnectionAcquireError and
ConnectionPasswordRequiredAcquireError carry prose. A failure during
session initialization can go either way, hence the split between
InitializationConnectionLossAcquireError and
InitializationServerErrorAcquireError.
Constructors
| ConnectionAcquireError | The connection could not be established, and no structured signal exists to say why. This is the residual case at the connection stage: DNS failure,
connection refused, TLS negotiation failure, a rejected password, a
missing database, and any other rejection |
Fields
| |
| ConnectionPasswordRequiredAcquireError | The server demanded a password and none was available. Reported from |
Fields
| |
| VersionTooOldAcquireError | The server's version is below the minimum this driver supports. The three fields are the server's major, minor and patch version, in
that order. The minimum required version is not carried alongside
them: it is a constant of this library, currently |
| InitializationConnectionLossAcquireError | Session initialization failed and the connection died: there is prose and nothing else. This covers both |
Fields
| |
| InitializationServerErrorAcquireError ServerError | Session initialization failed and the server said why. The server rejected the initialization statement and returned a real
error report, readable through |
Instances
| Eq AcquireError # | |
Defined in Hasql.Engine.Errors | |
| Show AcquireError # | |
Defined in Hasql.Engine.Errors Methods showsPrec :: Int -> AcquireError -> ShowS # show :: AcquireError -> String # showList :: [AcquireError] -> ShowS # | |
| IsError AcquireError # | |
Defined in Hasql.Errors Methods toMessage :: AcquireError -> Text # toDetails :: AcquireError -> [(Text, Text)] # toSqlState :: AcquireError -> Maybe Text # | |
Use errors
Error that use can return.
SessionUseError means the connection is still usable and is the only
constructor catchError on a Session
can see. ConnectionUseError means the connection is gone, and no handler
inside the session can intercept it - the split is structural, enforced by
the Session Monad instance rather than by any check a
handler has to remember to make.
Constructors
| SessionUseError SessionError | The session reported an ordinary failure and the connection is still usable. |
| ConnectionUseError | The connection is gone. This covers every way
Whatever the cause, the driver cannot vouch for the protocol state of
a connection a request failed to leave, and repairing one costs more
than replacing it: the repair would have to push a Sync, which
flushes and commits the very commands the failed session never got to
complete. So this is reported uniformly rather than split by cause -
retry policy belongs to the caller, informed by the reason text and,
for server errors, |
Fields
| |
Session errors
data SessionError #
Error that occurs during session execution and leaves the connection usable.
A session is a batch of actions executed in a database connection context.
Every constructor here means the connection is still fit to be handed
back for reuse - that is the axis SessionError is narrowed on, not
provenance. A failure that leaves the connection gone is not a
SessionError at all; it is one of the other two constructors of
UseError.
Session errors provide detailed context to help diagnose problems, including SQL text, parameters, and the location of the error within a pipeline of statements.
Constructors
| StatementSessionError | An error occurred while executing a statement in the session. This wraps statement-level errors and provides additional context about:
The error message includes formatted output showing all this context, making it easier to diagnose issues in production. |
Fields
| |
| ScriptSessionError | An error occurred while executing a script. Scripts are multi-statement SQL texts executed via |
Fields
| |
| MissingTypesSessionError | One or more types referenced in the statement could not be found in the database. This occurs when using custom types (enums, composite types, domains) that are resolved by name at runtime, but the types don't exist in the database. To fix this error:
|
Instances
| Eq SessionError # | |
Defined in Hasql.Engine.Errors | |
| Show SessionError # | |
Defined in Hasql.Engine.Errors Methods showsPrec :: Int -> SessionError -> ShowS # show :: SessionError -> String # showList :: [SessionError] -> ShowS # | |
| IsError SessionError # | |
Defined in Hasql.Errors Methods toMessage :: SessionError -> Text # toDetails :: SessionError -> [(Text, Text)] # toSqlState :: SessionError -> Maybe Text # | |
| MonadError SessionError Session # | Ranges over |
Defined in Hasql.Engine.Contexts.Session Methods throwError :: SessionError -> Session a # catchError :: Session a -> (SessionError -> Session a) -> Session a # | |
data StatementError #
Error that occurs when executing a single statement.
Statement errors can be caused by server-side issues (SQL errors, constraint violations) or by mismatches between the decoder specification and the actual result structure (wrong number of rows/columns, type mismatches, or cell-level decoding failures).
Constructors
| ServerStatementError ServerError | The server rejected the statement and returned an error. This includes SQL syntax errors, constraint violations, permission errors, and any other error reported by PostgreSQL during statement execution. |
| UnexpectedRowCountStatementError | The statement returned a different number of rows than expected. This occurs when using result decoders like |
| UnexpectedColumnCountStatementError | The statement returned a different number of columns than expected. This indicates a mismatch between the decoder specification and the actual result structure, possibly due to:
|
| UnexpectedColumnTypeStatementError | A column has a different type than expected. This occurs when the decoder expects a specific PostgreSQL type (by OID) but the actual column has a different type. This can happen due to:
Note: As of version 1.10, Hasql performs strict type checking and will report this error instead of attempting automatic type coercion. |
| RowStatementError | An error occurred while decoding a specific row. This wraps errors that occur at the row or cell level, providing context about which row failed. |
| UnexpectedResultStatementError | The database returned an unexpected result structure. This is a catch-all error that indicates either:
|
Fields
| |
Instances
| Eq StatementError # | |
Defined in Hasql.Engine.Errors Methods (==) :: StatementError -> StatementError -> Bool # (/=) :: StatementError -> StatementError -> Bool # | |
| Show StatementError # | |
Defined in Hasql.Engine.Errors Methods showsPrec :: Int -> StatementError -> ShowS # show :: StatementError -> String # showList :: [StatementError] -> ShowS # | |
| IsError StatementError # | |
Defined in Hasql.Errors Methods toMessage :: StatementError -> Text # toDetails :: StatementError -> [(Text, Text)] # toSqlState :: StatementError -> Maybe Text # | |
Error that occurs when decoding a result row.
Row errors indicate problems when processing an individual row from the result set, either at the cell level or during row refinement/validation.
Constructors
| CellRowError | An error occurred while decoding a specific cell in the row. This wraps cell-level errors (null handling, deserialization failures) and provides context about which column failed and its type. |
| RefinementRowError | A refinement or validation error when processing the row. This occurs when using refinement functions in row decoders
(e.g., with |
Fields
| |
Error that occurs when decoding a single cell (column value) in a result row.
Cell errors indicate problems with individual values returned by the database, such as unexpected nulls or failures in binary deserialization.
Constructors
| UnexpectedNullCellError | A NULL value was encountered when a non-NULL value was expected. This occurs when using non-nullable decoders (e.g., |
| DeserializationCellError | Failed to deserialize the cell value from its binary representation. This can occur when:
|
Fields
| |
data ServerError #
Error reported by the PostgreSQL server when executing a statement.
The server provides structured error information including error codes (SQL state), messages, and optional context like hints and position information.
For a complete list of PostgreSQL error codes, see: https://www.postgresql.org/docs/current/errcodes-appendix.html
Constructors
| ServerError | |
Fields
| |
Instances
| Eq ServerError # | |
Defined in Hasql.Engine.Errors | |
| Show ServerError # | |
Defined in Hasql.Engine.Errors Methods showsPrec :: Int -> ServerError -> ShowS # show :: ServerError -> String # showList :: [ServerError] -> ShowS # | |
| IsError ServerError # | |
Defined in Hasql.Errors Methods toMessage :: ServerError -> Text # toDetails :: ServerError -> [(Text, Text)] # toSqlState :: ServerError -> Maybe Text # | |