package octez-proto-libs

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type error_category = [
  1. | `Branch
  2. | `Temporary
  3. | `Permanent
  4. | `Outdated
]

CORE : errors

type error = ..
val error_encoding : error Data_encoding.t
val pp : Format.formatter -> error -> unit

EXT : error registration/query

val 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
val json_of_error : error -> Data_encoding.json
val error_of_json : Data_encoding.json -> error
type error_info = {
  1. category : error_category;
  2. id : string;
  3. title : string;
  4. description : string;
  5. schema : Data_encoding.json_schema;
}
val pp_info : Format.formatter -> error_info -> unit
val get_registered_errors : unit -> error_info list

Retrieves information of registered errors

MONAD : trace, monad, etc.

type 'err trace
type 'a tzresult = ('a, error trace) Pervasives.result
val make_trace_encoding : 'error Data_encoding.t -> 'error trace Data_encoding.t
val trace_encoding : error trace Data_encoding.t
val pp_trace : Format.formatter -> error trace -> unit
val result_encoding : 'a Data_encoding.t -> 'a tzresult Data_encoding.t
val ok : 'a -> ('a, 'trace) Pervasives.result
val return : 'a -> ('a, 'trace) Pervasives.result Lwt.t
val return_unit : (unit, 'trace) Pervasives.result Lwt.t
val return_none : ('a option, 'trace) Pervasives.result Lwt.t
val return_some : 'a -> ('a option, 'trace) Pervasives.result Lwt.t
val return_nil : ('a list, 'trace) Pervasives.result Lwt.t
val return_true : (bool, 'trace) Pervasives.result Lwt.t
val return_false : (bool, 'trace) Pervasives.result Lwt.t
val error : 'err -> ('a, 'err trace) Pervasives.result
val trace_of_error : 'err -> 'err trace
val tzfail : 'err -> ('a, 'err trace) Pervasives.result Lwt.t
val record_trace : 'err -> ('a, 'err trace) Pervasives.result -> ('a, 'err trace) Pervasives.result
val trace : 'err -> ('b, 'err trace) Pervasives.result Lwt.t -> ('b, 'err trace) Pervasives.result Lwt.t
val record_trace_eval : (unit -> 'err) -> ('a, 'err trace) Pervasives.result -> ('a, 'err trace) Pervasives.result
val trace_eval : (unit -> 'err) -> ('b, 'err trace) Pervasives.result Lwt.t -> ('b, 'err trace) Pervasives.result Lwt.t
val error_unless : bool -> 'err -> (unit, 'err trace) Pervasives.result
val error_when : bool -> 'err -> (unit, 'err trace) Pervasives.result
val fail_unless : bool -> 'err -> (unit, 'err trace) Pervasives.result Lwt.t
val fail_when : bool -> 'err -> (unit, 'err trace) Pervasives.result Lwt.t
val unless : bool -> (unit -> (unit, 'trace) Pervasives.result Lwt.t) -> (unit, 'trace) Pervasives.result Lwt.t
val when_ : bool -> (unit -> (unit, 'trace) Pervasives.result Lwt.t) -> (unit, 'trace) Pervasives.result Lwt.t
val dont_wait : (exn -> unit) -> ('trace -> unit) -> (unit -> (unit, 'trace) Pervasives.result Lwt.t) -> unit
val catch : ?catch_only:(exn -> bool) -> (unit -> 'a) -> 'a tzresult

catch f executes f within a try-with block and wraps exceptions within a tzresult. catch f is equivalent to try Ok (f ()) with e -> Error (error_of_exn e).

If catch_only is set, then only exceptions e such that catch_only e is true are caught.

Whether catch_only is set or not, this function never catches non-deterministic runtime exceptions of OCaml such as Stack_overflow and Out_of_memory nor system-exceptions such as Unix.Unix_error and Sys_error.

val catch_f : ?catch_only:(exn -> bool) -> (unit -> 'a) -> (exn -> error) -> 'a tzresult

catch_f f handler is equivalent to map_error (catch f) handler. In other words, it catches exceptions in f () and either returns the value in an Ok or passes the exception to handler for the Error.

catch_only has the same use as with catch. The same restriction on catching non-deterministic runtime exceptions applies.

val catch_s : ?catch_only:(exn -> bool) -> (unit -> 'a Lwt.t) -> 'a tzresult Lwt.t

catch_s is like catch but when f returns a promise. It is equivalent to

Lwt.try_bind f
  (fun v -> Lwt.return (Ok v))
  (fun e -> Lwt.return (Error (error_of_exn e)))

If catch_only is set, then only exceptions e such that catch_only e is true are caught.

Whether catch_only is set or not, this function never catches non-deterministic runtime exceptions of OCaml such as Stack_overflow and Out_of_memory nor system-exceptions such as Unix.Unix_error and Sys_error.

val join_e : (unit, 'err trace) Pervasives.result list -> (unit, 'err trace) Pervasives.result
val all_e : ('a, 'err trace) Pervasives.result list -> ('a list, 'err trace) Pervasives.result
val both_e : ('a, 'err trace) Pervasives.result -> ('b, 'err trace) Pervasives.result -> ('a * 'b, 'err trace) Pervasives.result
OCaml

Innovation. Community. Security.