improve bin pretty printing of errors

This commit is contained in:
Galfour 2019-06-06 17:37:46 +00:00
parent bff14309e4
commit 0fea1c6d78

View File

@ -1,11 +1,34 @@
open Cmdliner open Cmdliner
open Trace 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 = let toplevel x =
match x with match x with
| Trace.Ok ((), annotations) -> ignore annotations; () | Trace.Ok ((), annotations) -> ignore annotations; ()
| Error ss -> | Error ss -> (
Format.printf "%a%!" error_pp (ss ()) Format.printf "%a%!" error_pp (ss ())
)
let main = let main =
let term = Term.(const print_endline $ const "Ligo needs a command. Do ligo --help") in let term = Term.(const print_endline $ const "Ligo needs a command. Do ligo --help") in