package caqti

  1. Overview
  2. Docs

Error descriptors.

Messages

type msg = ..

In this type, drivers can stash information about an errors in ther own format, which can later be used for pretty-printing and or future operations. Drivers must define_msg on each constructor added to this type.

val define_msg : pp:(Stdlib.Format.formatter -> msg -> unit) -> extension_constructor -> unit

Mandatory registration of pretty-printer for a driver-supplied error descriptor.

val pp_msg : Stdlib.Format.formatter -> msg -> unit

pp_msg ppf msg formats msg on ppf.

type msg +=
  1. | Msg : string -> msg
    (*

    The shape of locally generated messages and messages from drivers without dedicated error type.

    *)

Messages with Metadata

Note. Please consider the fields internal for now, they may still be revised or hidden.

type load_error = private {
  1. uri : Uri.t;
  2. msg : msg;
}
type connection_error = private {
  1. uri : Uri.t;
  2. msg : msg;
}
type query_error = private {
  1. uri : Uri.t;
  2. query : string;
  3. msg : msg;
}
type coding_error = private {
  1. uri : Uri.t;
  2. typ : Caqti_type.any;
  3. msg : msg;
}

Documented Constructors

Errors during Driver Loading

val load_rejected : uri:Uri.t -> msg -> [> `Load_rejected of load_error ]

load_rejected ~uri msg indicates that a driver could not be identified from uri.

val load_failed : uri:Uri.t -> msg -> [> `Load_failed of load_error ]

load_failed ~uri msg indicates that a driver for uri could not be loaded.

Errors during Connect

val connect_rejected : uri:Uri.t -> msg -> [> `Connect_rejected of connection_error ]

connect_rejected ~uri msg indicates that the driver rejected the URI.

val connect_failed : uri:Uri.t -> msg -> [> `Connect_failed of connection_error ]

connect_failed ~uri msg indicates that the driver failed to establish a connection to the database.

Errors during Call

val encode_missing : uri:Uri.t -> field_type:'a Caqti_type.field -> unit -> [> `Encode_rejected of coding_error ]

encode_missing ~uri ~field_type () indicates that the driver does not support field_type and no fallback encoding is available for the type.

val encode_rejected : uri:Uri.t -> typ:'a Caqti_type.t -> msg -> [> `Encode_rejected of coding_error ]

encode_rejected ~uri ~typ msg indicates that encoding a value to typ failed, e.g. due to being out of range.

val encode_failed : uri:Uri.t -> typ:'a Caqti_type.t -> msg -> [> `Encode_failed of coding_error ]

encode_failed ~uri ~typ msg indicates that a parameter of type typ was not accepted by the database client library.

val request_rejected : uri:Uri.t -> query:string -> msg -> [> `Request_rejected of query_error ]

request_rejected ~uri ~query msg indicates that query was not accepted by the database or driver.

val request_failed : uri:Uri.t -> query:string -> msg -> [> `Request_failed of query_error ]

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

val decode_missing : uri:Uri.t -> field_type:'a Caqti_type.field -> unit -> [> `Decode_rejected of coding_error ]

decode_missing ~uri ~field_type () indicates that the driver does not support field_type for decoding result rows.

val decode_rejected : uri:Uri.t -> typ:'a Caqti_type.t -> msg -> [> `Decode_rejected of coding_error ]

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.

val response_failed : uri:Uri.t -> query:string -> msg -> [> `Response_failed of query_error ]

response_failed ~uri ~query msg indicates that something when wrong while fetching a delayed part of the response.

val response_rejected : uri:Uri.t -> query:string -> msg -> [> `Response_rejected of query_error ]

response_rejected ~uri ~query msg indicates that the response from the database was rejected due to requirements posed by client code.

Specific Error Types

type call = [
  1. | `Encode_rejected of coding_error
  2. | `Encode_failed of coding_error
  3. | `Request_rejected of query_error
  4. | `Request_failed of query_error
  5. | `Response_rejected of query_error
]
type retrieve = [
  1. | `Decode_rejected of coding_error
  2. | `Response_failed of query_error
  3. | `Response_rejected of query_error
]
type call_or_retrieve = [
  1. | call
  2. | retrieve
]
type transact = [
  1. | call
  2. | retrieve
]
type load = [
  1. | `Load_rejected of load_error
  2. | `Load_failed of load_error
]
type connect = [
  1. | `Connect_rejected of connection_error
  2. | `Connect_failed of connection_error
  3. | `Post_connect of call_or_retrieve
]
type load_or_connect = [
  1. | load
  2. | connect
]

Generic Error Type and Functions

type t = [
  1. | load
  2. | connect
  3. | call
  4. | retrieve
]

The full union of errors used by Caqti.

val uri : [< t ] -> Uri.t

uri error is the URI of the connection used where error occurred.

val pp : Stdlib.Format.formatter -> [< t ] -> unit

pp ppf error prints an explanation of error on ppf.

val show : [< t ] -> string

show error is an explanation of error.

val uncongested : ('a, [< t | `Congested of Caqti_common.counit ]) Stdlib.result -> ('a, [> t ]) Stdlib.result

uncongested r eliminates an unused `Congested case from the error.

exception Exn of t

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.