package octez-libs

  1. Overview
  2. Docs
A package that contains multiple base libraries used by the Octez suite

Install

Dune Dependency

Authors

Maintainers

Sources

tezos-octez-v20.1.tag.bz2
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65

doc/octez-libs.error-monad/Tezos_error_monad/TzCore/index.html

Module Tezos_error_monad.TzCoreSource

Sourcetype error_category = [
  1. | `Branch
    (*

    Errors that may not happen in another context

    *)
  2. | `Temporary
    (*

    Errors that may not happen in a later context

    *)
  3. | `Permanent
    (*

    Errors that will happen no matter the context

    *)
]
Sourcetype error = ..
include Sig.CORE with type error := error and type error_category := error_category
Sourceval string_of_category : error_category -> string
Sourceval error_encoding : error Data_encoding.t

The encoding for errors.

Note that this encoding has a few peculiarities, some of which may impact your code. These peculiarities are due to the type error being an extensible variant.

Because the error type is an extensible variant, you must register an encoding for each error constructor you add to error. This is done via register_error_kind.

Because the error type is an extensible variant, with dynamically registered errors (see peculiarity above), there are no tags associated with each error. This does not affect the JSON encoding, but it does impose restrictions on the binary encoding. The chosen workaround is to encode errors as JSON and to encode the JSON to binary form. As a result, errors can be somewhat large in binary: they include field names and such.

Because the error type is an extensible variant, with dynamically registered errors (see peculiarity above), the encoding must be recomputed when a new error is registered. This is achieved by the means of a Data_encoding.delayed combinator: the encoding is recomputed on-demand. There is a caching mechanism so that, in the case where no new errors have been registered since the last use, the last result is used.

This last peculiarity imposes a limit on the use of error_encoding itself. Specifically, it is invalid to use error_encoding inside the ~json argument of a Data_encoding.splitted. This is because splitted evaluates the delayed combinator once-and-for-all to produce a json encoding. (Note that the following data-encoding combinators use splitted internally: Data_encoding.Compact.make, Data_encoding.assoc, and Data_encoding.lazy_encoding. As a result, it is invalid to use error_encoding within the arguments of these combinators as well.)

Sourceval pp : Format.formatter -> error -> unit
Sourceval register_error_kind : 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

Sourceval classify_error : error -> Error_classification.t

Classify an error using the registered kinds

Sourcetype error += private
  1. | Unclassified of string

Catch all error when 'serializing' an error.

Sourcetype error += private
  1. | Unregistered_error of Data_encoding.json

Catch all error when 'deserializing' an error.

Sourceval json_of_error : error -> Data_encoding.json

An error serializer

Sourceval error_of_json : Data_encoding.json -> error

Error documentation

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

Error information

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

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

  • raises Not_found

    if the error's constructor has not been registered

Sourceval get_registered_errors : unit -> error_info list

Retrieves information of registered errors

include Sig.WITH_WRAPPED with type error := error
Sourcemodule 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.

Sourceval 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.