tezos-base
Library
Module
Module type
Parameter
Class
Class type
type error_category = [
| `Branch | (* Errors that may not happen in another context *) |
| `Temporary | (* Errors that may not happen in a later context *) |
| `Permanent | (* Errors that will happen no matter the context *) |
]
Categories of error
include Tezos_error_monad.Sig.CORE
val error_encoding : error Data_encoding.t
val pp : Format.formatter -> error -> unit
val register_error_kind :
Tezos_error_monad.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 classify_error : error -> Tezos_error_monad.Sig.error_category
Classify an error using the registered kinds
include Tezos_error_monad.Sig.EXT with type error := error
Catch all error when 'serializing' an error.
val json_of_error : error -> Data_encoding.json
An error serializer
val error_of_json : Data_encoding.json -> error
Error documentation
type error_info = {
category : Tezos_error_monad.Sig.error_category; |
id : string; |
title : string; |
description : string; |
schema : Data_encoding.json_schema; |
}
Error information
val pp_info : Format.formatter -> error_info -> unit
val get_registered_errors : unit -> error_info list
Retrieves information of registered errors
include Tezos_error_monad.Sig.WITH_WRAPPED with type error := error
module type Wrapped_error_monad = sig ... end
val register_wrapped_error_kind :
(module Wrapped_error_monad) ->
id:string ->
title:string ->
description:string ->
unit
include Tezos_error_monad.Sig.MONAD with type error := error
type trace = error list
A trace
is a stack of error
s. It is implemented as an error list
but such a list MUST NEVER be empty.
It is implemented as a concrete error list
for backwards compatibility but future improvements might modify the type or render the type abstract.
val pp_print_error : Format.formatter -> trace -> unit
val trace_encoding : trace Data_encoding.t
val classify_errors : trace -> Tezos_error_monad.Sig.error_category
val result_encoding : 'a Data_encoding.t -> 'a tzresult Data_encoding.t
A serializer for result of a given type
val ok : 'a -> 'a tzresult
Sucessful result
Enrich an error report (or do nothing on a successful result) manually
Automatically enrich error reporting on stack rewind
Same as record_trace, for unevaluated error
Same as trace, for unevaluated Lwt error
val _assert :
bool ->
string ->
( 'a, Format.formatter, unit, unit tzresult Lwt.t ) format4 ->
'a
In-monad list iterators
A List.iter
in the monad
A List.map2
in the monad
A List.filter_map
in the monad
A List.filter
in the monad
A List.fold_left
in the monad
A List.fold_right
in the monad
val generic_error : ( 'a, Format.formatter, unit, 'b tzresult ) format4 -> 'a
Erroneous result (shortcut for generic errors)
val failwith : ( 'a, Format.formatter, unit, 'b tzresult Lwt.t ) format4 -> 'a
Erroneous return (shortcut for generic errors)
val error_exn : exn -> 'a tzresult
val pp_exn : Format.formatter -> exn -> unit
val failure : ( 'a, Format.formatter, unit, error ) format4 -> 'a
Wrapped OCaml/Lwt exception
val protect :
?on_error:( trace -> 'a tzresult Lwt.t ) ->
?canceler:Lwt_canceler.t ->
( unit -> 'a tzresult Lwt.t ) ->
'a tzresult Lwt.t
protect
is a wrapper around Lwt.catch
where the error handler operates over `trace` instead of `exn`. Besides, protect ~on_error ~canceler ~f
may *cancel* f
via a Lwt_canceler.t
.
More precisely, protect ~on_error ~canceler f
runs f ()
. An Lwt failure triggered by f ()
is wrapped into an Exn
. If a canceler
is given and Lwt_canceler.cancellation canceler
is determined before f ()
, a Canceled
error is returned.
Errors are caught by ~on_error
(if given), otherwise the previous value is returned. An Lwt failure triggered by ~on_error
is wrapped into an Exn
val with_timeout :
?canceler:Lwt_canceler.t ->
unit Lwt.t ->
( Lwt_canceler.t -> 'a tzresult Lwt.t ) ->
'a tzresult Lwt.t
module Make (Prefix : Tezos_error_monad.Sig.PREFIX) : sig ... end