| 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:
ConnectionError- errors that occur when establishing a database connectionSessionError- 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 ConnectionError
- data SessionError
- data StatementError
- data RowError
- data CellError
- data ServerError = ServerError Text Text (Maybe Text) (Maybe Text) (Maybe Int)
Error class
class IsError a where Source #
A class for types that can be treated as errors.
Methods
toMessage :: a -> Text Source #
Convert the error to a human-readable message with no dynamic details.
toDetails :: a -> [(Text, Text)] Source #
Convert the error to a list of key-value pairs of dynamic details.
isTransient :: a -> Bool Source #
Whether the error is transient and the operation causing it can be retried.
Instances
| IsError CellError Source # | |
| IsError ConnectionError Source # | |
Defined in Hasql.Errors Methods toMessage :: ConnectionError -> Text Source # toDetails :: ConnectionError -> [(Text, Text)] Source # isTransient :: ConnectionError -> Bool Source # | |
| IsError RowError Source # | |
| IsError ServerError Source # | |
Defined in Hasql.Errors Methods toMessage :: ServerError -> Text Source # toDetails :: ServerError -> [(Text, Text)] Source # isTransient :: ServerError -> Bool Source # | |
| IsError SessionError Source # | |
Defined in Hasql.Errors Methods toMessage :: SessionError -> Text Source # toDetails :: SessionError -> [(Text, Text)] Source # isTransient :: SessionError -> Bool Source # | |
| IsError StatementError Source # | |
Defined in Hasql.Errors Methods toMessage :: StatementError -> Text Source # toDetails :: StatementError -> [(Text, Text)] Source # isTransient :: StatementError -> Bool Source # | |
toDetailedText :: IsError e => e -> Text Source #
Convert the error to a multiline detailed human-readable text representation containing all details.
Connection errors
data ConnectionError Source #
Error that occurs when attempting to establish a database connection.
These errors can occur when calling acquire.
Connection errors are categorized into several types to help with
error handling and logging.
Constructors
| NetworkingConnectionError | Network-level error while connecting to the database server. This typically indicates issues like:
These errors are transient and the operation can be retried. |
Fields
| |
| AuthenticationConnectionError | Authentication failed when connecting to the database. This typically indicates issues like:
These errors are not transient and require fixing the credentials or permissions. |
Fields
| |
| CompatibilityConnectionError | Compatibility issue between client and server. This typically indicates issues like:
These errors are not transient and require upgrading/downgrading the server or client. |
Fields
| |
| OtherConnectionError | Uncategorized error coming from This is a catch-all for connection errors that don't fit into other categories.
The error message may be empty if These errors are not transient by default. |
Fields
| |
Instances
| Show ConnectionError Source # | |
Defined in Hasql.Engine.Errors Methods showsPrec :: Int -> ConnectionError -> ShowS # show :: ConnectionError -> String # showList :: [ConnectionError] -> ShowS # | |
| Eq ConnectionError Source # | |
Defined in Hasql.Engine.Errors Methods (==) :: ConnectionError -> ConnectionError -> Bool # (/=) :: ConnectionError -> ConnectionError -> Bool # | |
| IsError ConnectionError Source # | |
Defined in Hasql.Errors Methods toMessage :: ConnectionError -> Text Source # toDetails :: ConnectionError -> [(Text, Text)] Source # isTransient :: ConnectionError -> Bool Source # | |
Session errors
data SessionError Source #
Error that occurs during session execution.
A session is a batch of actions executed in a database connection context. Session errors can occur due to statement failures, connection issues, missing types, or internal driver errors.
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
| |
| ConnectionSessionError | A connection-level error occurred during session execution. This indicates that the connection to the database was lost or became unusable during the session. These errors are transient and the operation can be retried with a new connection. Note: As of version 1.10, connections recover from async exceptions without resetting, preserving connection-local state. |
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:
|
| DriverSessionError | An internal driver error occurred. This indicates either:
If you encounter this error, please report it as a bug. |
Fields
| |
Instances
| Show SessionError Source # | |
Defined in Hasql.Engine.Errors Methods showsPrec :: Int -> SessionError -> ShowS # show :: SessionError -> String # showList :: [SessionError] -> ShowS # | |
| Eq SessionError Source # | |
Defined in Hasql.Engine.Errors | |
| IsError SessionError Source # | |
Defined in Hasql.Errors Methods toMessage :: SessionError -> Text Source # toDetails :: SessionError -> [(Text, Text)] Source # isTransient :: SessionError -> Bool Source # | |
| MonadError SessionError Session Source # | |
Defined in Hasql.Engine.Contexts.Session Methods throwError :: SessionError -> Session a # catchError :: Session a -> (SessionError -> Session a) -> Session a # | |
data StatementError Source #
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
| Show StatementError Source # | |
Defined in Hasql.Engine.Errors Methods showsPrec :: Int -> StatementError -> ShowS # show :: StatementError -> String # showList :: [StatementError] -> ShowS # | |
| Eq StatementError Source # | |
Defined in Hasql.Engine.Errors Methods (==) :: StatementError -> StatementError -> Bool # (/=) :: StatementError -> StatementError -> Bool # | |
| IsError StatementError Source # | |
Defined in Hasql.Errors Methods toMessage :: StatementError -> Text Source # toDetails :: StatementError -> [(Text, Text)] Source # isTransient :: StatementError -> Bool Source # | |
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 Source #
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
| Show ServerError Source # | |
Defined in Hasql.Engine.Errors Methods showsPrec :: Int -> ServerError -> ShowS # show :: ServerError -> String # showList :: [ServerError] -> ShowS # | |
| Eq ServerError Source # | |
Defined in Hasql.Engine.Errors | |
| IsError ServerError Source # | |
Defined in Hasql.Errors Methods toMessage :: ServerError -> Text Source # toDetails :: ServerError -> [(Text, Text)] Source # isTransient :: ServerError -> Bool Source # | |