From 4fa11bdf28aa41abd24a3d20471c5388ad17fdfc Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 13 Feb 2018 11:52:23 +0100 Subject: [PATCH] Error_monad: improve error message for unrecognized errors --- src/lib_error_monad/error_monad.ml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib_error_monad/error_monad.ml b/src/lib_error_monad/error_monad.ml index 5c0c43fca..8baefe88d 100644 --- a/src/lib_error_monad/error_monad.ml +++ b/src/lib_error_monad/error_monad.ml @@ -413,6 +413,8 @@ module Make() = struct (Format.pp_print_list pp) (List.rev errors) + + (** Catch all error when 'serializing' an error. *) type error += Unclassified of string let () = @@ -439,6 +441,25 @@ module Make() = struct 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 "@[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 let () =