Error_monad: improve error message for unrecognized errors

This commit is contained in:
bruno 2018-02-13 11:52:23 +01:00 committed by Grégoire Henry
parent 77bd0af3d1
commit 4fa11bdf28

View File

@ -413,6 +413,8 @@ module Make() = struct
(Format.pp_print_list pp) (Format.pp_print_list pp)
(List.rev errors) (List.rev errors)
(** Catch all error when 'serializing' an error. *)
type error += Unclassified of string type error += Unclassified of string
let () = let () =
@ -439,6 +441,25 @@ module Make() = struct
error_kinds := error_kinds :=
Error_kind { id ; from_error ; category ; encoding_case ; pp } :: !error_kinds Error_kind { id ; from_error ; category ; encoding_case ; pp } :: !error_kinds
(** Catch all error when 'deserializing' an error. *)
type error += Unregistred_error of Data_encoding.json
let () =
let id = "" in
let category = `Temporary in
let to_error msg = Unregistred_error msg in
let from_error = function
| Unregistred_error json -> Some json
| _ -> None in
let encoding_case =
let open Data_encoding in
case Json_only json from_error to_error in
let pp ppf json =
Format.fprintf ppf "@[<v 2>Unregistred error:@ %a@]"
Data_encoding.Json.pp json in
error_kinds :=
Error_kind { id ; from_error ; category ; encoding_case ; pp } :: !error_kinds
type error += Assert_error of string * string type error += Assert_error of string * string
let () = let () =