[log] log dying message and backtrace to log file

Summary:
Previously we wouldn't flush the formatter hence the error message would
generally not make it to the log file. Add the backtrace too, although only the
first few lines appear for some reason...

Reviewed By: ngorogiannis

Differential Revision: D9915499

fbshipit-source-id: 43cd9e36e
master
Jules Villard 6 years ago committed by Facebook Github Bot
parent 704c7cf680
commit 86f8f3e949

@ -17,14 +17,21 @@ exception InferUserError of string
exception InferExit of int
let raise_error error ~msg =
let raise_error ?backtrace error ~msg =
let do_raise exn =
match backtrace with
| None ->
raise exn
| Some backtrace ->
Caml.Printexc.raise_with_backtrace exn backtrace
in
match error with
| ExternalError ->
raise (InferExternalError msg)
do_raise (InferExternalError msg)
| InternalError ->
raise (InferInternalError msg)
do_raise (InferInternalError msg)
| UserError ->
raise (InferUserError msg)
do_raise (InferUserError msg)
let log_uncaught_exception_callback_ref = ref (fun _ ~exitcode:_ -> ())

@ -32,7 +32,7 @@ val log_uncaught_exception : exn -> exitcode:int -> unit
val die : error -> ('a, Format.formatter, unit, _) format4 -> 'a
(** Raise the corresponding exception. *)
val raise_error : error -> msg:string -> 'a
val raise_error : ?backtrace:Caml.Printexc.raw_backtrace -> error -> msg:string -> 'a
type style = Error | Fatal | Normal | Warning

@ -304,7 +304,12 @@ let log_of_kind error fmt =
let die error msg =
F.kasprintf (fun msg -> log_of_kind error "%s@\n" msg ; raise_error error ~msg) msg
let backtrace = Caml.Printexc.get_raw_backtrace () in
F.kasprintf
(fun msg ->
log_of_kind error "%s@\n%s@." msg (Caml.Printexc.raw_backtrace_to_string backtrace) ;
raise_error ~backtrace error ~msg )
msg
(* create new channel from the log file, and dumps the contents of the temporary log buffer there *)

Loading…
Cancel
Save