Module Imandrakit_error.Error

Universal error type for Imandrakit.

Exposes the standard errors that Imandrakit can raise.

include module type of Error_core
type message = {
  1. msg : string;
  2. data : Data.t;
  3. bt : string option;
    (*

    Backtrace

    *)
}

A message.

An error message is emitted at a particular place in the code. An error can contain several error messages.

type stack = message list
type t = {
  1. process : string;
  2. kind : Kind.t;
  3. msg : message;
  4. stack : stack;
}
exception E of t

Internal error

val pp_with : show_process:bool -> t Imandrakit_common.Fmt.printer
module Message : sig ... end
val data : t -> Data.t
val get_data : 'a Data.key -> t -> 'a option
val raise_err : ?bt:Stdlib.Printexc.raw_backtrace -> t -> 'a
val add_bt : string -> t -> t
val add_ctx : message -> t -> t
val add_data : 'a Data.key -> 'a -> t -> t
val guard : ?let_pass:(exn -> bool) -> (unit -> message) -> (unit -> 'a) -> 'a

guard g f behaves like f(), excepts that if f() raises Error e, guard g f raises Error e' where e' wraps e with context error g().

  • parameter let_pass

    if it returns true for an exception, the exception is re-raised.

type !'a result = ('a, t) result
val map_result : ('a -> 'b) -> 'a result -> 'b result
val unwrap : 'a result -> 'a

unwrap e uses raise_err to unpack the result

module Infix : sig ... end
include module type of Infix
val let*! : (unit -> message) -> (unit -> 'a) -> 'a

Similar to guard

module Kind = Kind
val fail : ?stack:message list -> ?process:string -> ?bt:string -> kind:Kind.t -> string -> 'a

fail "some error message" raises an error with the given message

val failf : ?stack:message list -> ?process:string -> ?bt:string -> kind:Kind.t -> ('a, Stdlib.Format.formatter, unit, 'b) format4 -> 'a

errorf "some error message %s (number %d)" "with formatting" 42 raises an error with the given formatted message

val mk_error : ?stack:message list -> ?process:string -> ?bt:string -> kind:Kind.t -> string -> t
val mk_errorf : ?stack:message list -> ?process:string -> ?bt:string -> kind:Kind.t -> ('a, Stdlib.Format.formatter, unit, t) format4 -> 'a
val message : ?bt:string -> string -> message
val messagef : ?bt:string -> ('a, Stdlib.Format.formatter, unit, message) format4 -> 'a
val guards : ?let_pass:(exn -> bool) -> string -> (unit -> 'a) -> 'a
val guardf : ?let_pass:(exn -> bool) -> ((('a, Stdlib.Format.formatter, unit, message) format4 -> 'a) -> message) -> (unit -> 'b) -> 'b

guardf ~loc k f behaves like f(), but will call k to produce a contextual message in case of error.

val of_exn : ?bt:Stdlib.Printexc.raw_backtrace -> kind:Kind.t -> exn -> t

Turn exception into an error.

val try_catch : kind:Kind.t -> unit -> (unit -> 'a) -> 'a result
val unwrap_opt : 'a option -> 'a