From 0fea1c6d784473d0cbd1adfba79a288b67697626 Mon Sep 17 00:00:00 2001 From: Galfour Date: Thu, 6 Jun 2019 17:37:46 +0000 Subject: [PATCH] improve bin pretty printing of errors --- src/bin/cli.ml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/bin/cli.ml b/src/bin/cli.ml index a17822a8b..b8423fc89 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -1,11 +1,34 @@ open Cmdliner open Trace +let error_pp out (e : error) = + let open JSON_string_utils in + let message = + let opt = e |> member "message" |> string in + let msg = Option.unopt ~default:"" opt in + ": " ^ msg in + let error_code = + let error_code = e |> member "error_code" in + match error_code with + | `Null -> "" + | _ -> " (" ^ (J.to_string error_code) ^ ")" in + let title = + let opt = e |> member "title" |> string in + Option.unopt ~default:"" opt in + let data = + let data = e |> member "data" in + match data with + | `Null -> "" + | _ -> " " ^ (J.to_string data) ^ "\n" in + Format.fprintf out "%s%s%s.\n%s" title error_code message data + + let toplevel x = match x with | Trace.Ok ((), annotations) -> ignore annotations; () - | Error ss -> + | Error ss -> ( Format.printf "%a%!" error_pp (ss ()) + ) let main = let term = Term.(const print_endline $ const "Ligo needs a command. Do ligo --help") in