package tezos-error-monad

  1. Overview
  2. Docs
type error = ..
include Sig.CORE with type error := error
val error_encoding : error Data_encoding.t
val pp : Format.formatter -> error -> unit
include Sig.EXT with type error := error
val register_error_kind : Sig.error_category -> id:string -> title:string -> description:string -> ?pp:(Format.formatter -> 'err -> unit) -> 'err Data_encoding.t -> (error -> 'err option) -> ('err -> error) -> unit

The error data type is extensible. Each module can register specialized error serializers id unique name of this error. Ex.: overflow_time_counter title more readable name. Ex.: Overflow of time counter description human readable description. Ex.: The time counter overflowed while computing delta increase pp formatter used to pretty print additional arguments. Ex.: The time counter overflowed while computing delta increase. Previous value %d. Delta: %d encoder decoder data encoding for this error. If the error has no value, specify Data_encoding.empty

val register_recursive_error_kind : Sig.error_category -> id:string -> title:string -> description:string -> pp:(Format.formatter -> 'err -> unit) -> (error Data_encoding.t -> 'err Data_encoding.t) -> (error -> 'err option) -> ('err -> error) -> unit

Same as register_error_kind but allow errors to wrap other errors.

The encoding argument is a function which will be given the encoding of errors as argument so that you can encode errors in errors using a fixpoint.

Another difference with register_error_kind is that pp is mandatory.

val classify_error : error -> Sig.error_category

Classify an error using the registered kinds

type error += private
  1. | Unclassified of string
    (*

    Catch all error when 'deserializing' an error.

    *)

Catch all error when 'serializing' an error.

type error += private
  1. | Unregistered_error of Data_encoding.json
val json_of_error : error -> Data_encoding.json

An error serializer

val error_of_json : Data_encoding.json -> error

Error documentation

type error_info = {
  1. category : Sig.error_category;
  2. id : string;
  3. title : string;
  4. description : string;
  5. schema : Data_encoding.json_schema;
}

Error information

val pp_info : Format.formatter -> error_info -> unit
val find_info_of_error : error -> error_info

find_info_of_error e retrieves the `error_info` associated with the given error `e`.

  • raises [Invalid_argument]

    if the error is a wrapped error from another monad

  • raises [Not_found]

    if the error's constructor has not been registered

val get_registered_errors : unit -> error_info list

Retrieves information of registered errors

include Sig.WITH_WRAPPED with type error := error
module type Wrapped_error_monad = sig ... end

The purpose of this module is to wrap a specific error monad E into a more general error monad Eg.

val register_wrapped_error_kind : (module Wrapped_error_monad) -> id:string -> title:string -> description:string -> unit

Same as register_error_kind but for a wrapped error monad. The codec is defined in the module parameter. It makes the category of the error Wrapped instead of Main.

OCaml

Innovation. Community. Security.