include module type of struct include Caqti.Error end
Error Causes
The cause type is an incomplete enumeration of consolidated causes of errors between different database systems. The selection includes the causes which are believed to be useful to handle and excludes causes which are specific to the implementation of a certain database system.
The causes are classified into subtypes to help matching them collectively. Each subtype has a fall-back case which is used if the database system does not clearly report one of the specific cases. An condition which is reported as the fall-back case may in a future version be reported as a specific case, possibly adding a new case to the subtype. Therefore, for backwards compatibility you should match the full subtype rather than the fall-back, e.g.
(match Caqti.Error.cause error with
| `Unique_violation -> handle_unique_violation ()
| #integrity_constraint_violation -> handle_other_constraint_violation ()
| _ -> handle_other_error ())
This ensures that your code stil compiles when a new case is added to integrity_constraint_violation, and that the error condition receiving mapped to the new case is still handled by the subtype pattern when you link to the new version of Caqti.
Currently we do not have access to the extended error codes from SQLite3, meaning that all integrity constraint violation conditions will be reported as `Integrity_constraint_violation__don't_match.
Since the consolitation of each error condition requires some investitation and testing, the selection made is very conservative. If you need to handle an error which is currently unlisted, please open an issue or create a pull request. A pull request should, if possible, include a extension of test_error_cause.ml to demonstrate how the error is triggered by the database systems.
Sourcetype integrity_constraint_violation = [ | `Restrict_violationThis is meant to indicate that a deletion or update would cause a foreign key violation, although this may be reported as a `Foreign_key_violation.
| `Not_null_violationAn insertion or update attempts to assign a NULL value to column having a NOT NULL constraint.
| `Foreign_key_violationAn modification would cause a column to reference a non-existing key. This cause may also be reported for cases which should have been covered by `Restrict_violation.
| `Unique_violationAn insertion or update would duplicate a key as declared by a UNIQUE or PRIMARY KEY constraint.
| `Check_violationA requested change would violate a CHECK constraint.
| `Exclusion_violationA requested insertion or update would cause an overlap of rows according to an EXCLUDE constraint.
| `Integrity_constraint_violation__don't_matchAn yet unclassified cause; match the full subtype instead.
] A subtype of cause informing about violation of SQL constraints.
Sourcetype insufficient_resources = [ | `Disk_fullThe server is out of disk space.
| `Out_of_memoryThe server is out of memory
| `Too_many_connectionsThe server does not accept establishing more connections.
| `Configuration_limit_exceededSome unspecific server limit is exceeded.
| `Insufficient_resources__don't_matchAn yet unclassified cause; match the full subtype instead.
] A subtype of cause informing about insufficient resources on the server side.
The selection of causes of errors which have been mapped.
Messages
In this type, drivers can stash information about any errors in their own format, which can later be used for pretty-printing and or future operations. Drivers must call define_msg on each constructor added to this type.
Mandatory registration of pretty-printer for a driver-supplied error descriptor.
pp_msg ppf msg formats msg on ppf.
Sourcetype msg += | Msg : string -> msgThe shape of locally generated messages and messages from drivers without dedicated error type.
Note. Please consider the fields internal for now, they may still be revised or hidden.
Documented Constructors
Errors during Driver Loading
load_rejected ~uri msg indicates that a driver could not be identified from uri.
load_failed ~uri msg indicates that a driver for uri could not be loaded.
Errors during Connect
connect_rejected ~uri msg indicates that the driver rejected the URI.
connect_failed ~uri msg indicates that the driver failed to establish a connection to the database.
Errors during Call
encode_missing ~uri ~field_type () indicates that the driver does not support field_type and no fallback encoding is available for the type.
encode_rejected ~uri ~typ msg indicates that encoding a value to typ failed, e.g. due to being out of range.
encode_failed ~uri ~typ msg indicates that a parameter of type typ was not accepted by the database client library.
request_failed ~uri ~query msg indicates that the request could not be transmitted to the database, that the database was not ready to process the request, or that something went wrong while processing the request.
Errors during Result Retrieval
decode_missing ~uri ~field_type () indicates that the driver does not support field_type for decoding result rows.
decode_rejected ~uri ~typ msg indicates that the driver could not decode a field of type typ from the returned row, e.g. due to an invalid value or limited range of the target type.
response_failed ~uri ~query msg indicates that something when wrong while fetching a delayed part of the response.
response_rejected ~uri ~query msg indicates that the response from the database was rejected due to requirements posed by client code.
Specific Error Types
Errors which may occur during retrival of result rows. This includes `Request_failed since the request is fused with retrieval for the pgx driver.
Generic Error Type and Functions
The full union of errors used by Caqti.
uri error is the URI of the connection used where error occurred.
pp ppf error prints an explanation of error on ppf.
show error is an explanation of error.
A matchable representation of the cause of the error, if available.
uncongested r eliminates an unused `Congested case from the error.
Exn error can be used when an exception is preferred over explicit error handling. The core Caqti API never raises exceptions which originate from runtime errors.