From 9cc963ce7bc91592a301feca1e2238bc17448bd8 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Wed, 22 Feb 2023 15:45:41 +1100 Subject: [PATCH] More consise error message printing --- lib/dev_repo.ml | 2 +- lib/duniverse.ml | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/dev_repo.ml b/lib/dev_repo.ml index 651ff9eca..30fbea196 100644 --- a/lib/dev_repo.ml +++ b/lib/dev_repo.ml @@ -5,7 +5,7 @@ type t = string let compare = String.compare let from_string s = s let to_string t = t -let pp fmt t = Format.fprintf fmt "%s" t +let pp = Fmt.string let rec repeat_while_some x ~f = match f x with None -> x | Some x -> repeat_while_some x ~f diff --git a/lib/duniverse.ml b/lib/duniverse.ml index 035edad3f..5abac2f9a 100644 --- a/lib/duniverse.ml +++ b/lib/duniverse.ml @@ -266,20 +266,16 @@ let dev_repo_package_map_to_repos dev_repo_package_map = | Some (dir, dev_repos) -> let dir_path = Fpath.(Config.vendor_dir / dir) in let message_first_line = - Format.asprintf - "Multiple dev-repos would be vendored into the directory: %a" + Fmt.str "Multiple dev-repos would be vendored into the directory: %a" Fpath.pp dir_path in - let message_dev_repos = - Format.sprintf "Dev-repos:\n%s" - (List.map dev_repos ~f:(fun dev_repo -> - Format.asprintf "- %a" Dev_repo.pp dev_repo) - |> String.concat ~sep:"\n") + let dev_repos_pp = + Fmt.list + ~sep:Fmt.(const char '\n') + (fun ppf dev_repo -> Fmt.pf ppf "- %a" Dev_repo.pp dev_repo) in - let message = - [ message_first_line; message_dev_repos ] |> String.concat ~sep:"\n" - in - Error (`Msg message) + Rresult.R.error_msgf "%s\nDev-repos:\n%a" message_first_line + dev_repos_pp dev_repos in Ok (List.map ~f:snd repo_by_dev_repo)