From 6120b7d098631439f74285c78829f203421ce116 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Thu, 10 Oct 2019 06:17:43 -0700 Subject: [PATCH] [sledge] Use the configured margin when formatting failure messages Reviewed By: bennostein Differential Revision: D17801934 fbshipit-source-id: af7acec9b --- sledge/src/import/import.ml | 7 ++++++- sledge/src/import/import.mli | 2 +- sledge/src/trace/trace.ml | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sledge/src/import/import.ml b/sledge/src/import/import.ml index 081e511fc..39161b2e0 100644 --- a/sledge/src/import/import.ml +++ b/sledge/src/import/import.ml @@ -65,9 +65,14 @@ let warn fmt = Format.pp_force_newline fs () ) fs fmt -let raisef exn fmt = +let raisef ?margin exn fmt = let bt = Caml.Printexc.get_raw_backtrace () in let fs = Format.str_formatter in + ( match margin with + | Some m -> + Format.pp_set_margin fs m ; + Format.pp_set_max_indent fs (m - 1) + | None -> () ) ; Format.pp_open_box fs 2 ; Format.kfprintf (fun fs () -> diff --git a/sledge/src/import/import.mli b/sledge/src/import/import.mli index 6d55ca012..d28e35bdc 100644 --- a/sledge/src/import/import.mli +++ b/sledge/src/import/import.mli @@ -77,7 +77,7 @@ type ('a, 'b) fmt = ('a, Formatter.t, unit, 'b) format4 exception Unimplemented of string -val raisef : (string -> exn) -> ('a, unit -> _) fmt -> 'a +val raisef : ?margin:int -> (string -> exn) -> ('a, unit -> _) fmt -> 'a (** Take a function from a string message to an exception, and a format string with the additional arguments it specifies, and then call the function on the formatted string and raise the returned exception. *) diff --git a/sledge/src/trace/trace.ml b/sledge/src/trace/trace.ml index 6e4f152cd..89cf9a426 100644 --- a/sledge/src/trace/trace.ml +++ b/sledge/src/trace/trace.ml @@ -167,7 +167,8 @@ let retn mod_name fun_name k result = result let fail fmt = - raisef + let margin = Format.pp_get_margin fs () in + raisef ~margin (fun msg -> Format.fprintf fs "@\n@[<2>| %s@]@." msg ; Failure msg )