[utils] catch exceptions in epilogues to allow all of them to run

Summary: This makes sure we give a chance to each epilogue to run.

Reviewed By: akotulski

Differential Revision: D4501230

fbshipit-source-id: bc903d0
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 9593ab69aa
commit 6faccb1490

@ -156,4 +156,4 @@ let register_report_at_exit file =
with exc ->
Format.eprintf "Info: failed to compute stats for %s@\n%s@\n%s@."
file (Exn.to_string exc) (Printexc.get_backtrace ())
)
) ("stats reporting in " ^ file)

@ -76,8 +76,9 @@ let create_log_file exe name_prefix outerr =
| `Err -> Format.err_formatter in
dup_formatter file_fmt outerr_fmt
);
(* flush files on exit *)
Utils.register_epilogue (fun () -> close_log_file (lazy file_fmt) (lazy chan) (lazy file));
Utils.register_epilogue
(fun () -> close_log_file (lazy file_fmt) (lazy chan) (lazy file))
"log files flushing";
(file_fmt, chan, file)
let should_setup_log_files (exe : CLOpt.exe) = match exe with

@ -302,8 +302,12 @@ let activate_run_epilogues_on_signal = lazy (
Signal.Expert.handle Signal.int run_epilogues_on_signal
)
let register_epilogue f =
let register_epilogue f desc =
let f_no_exn () =
try f ()
with exn ->
F.eprintf "Error while running epilogue %s:@ %a.@ Powering through...@." desc Exn.pp exn in
(* We call `exit` in a bunch of places, so register the epilogues with [at_exit]. *)
Pervasives.at_exit f;
Pervasives.at_exit f_no_exn;
(* Register signal masking. *)
Lazy.force activate_run_epilogues_on_signal

@ -88,4 +88,4 @@ val compare_versions : string -> string -> int
(** Register a function to run when the program exits or is interrupted. Registered functions are
run in the reverse order in which they were registered. *)
val register_epilogue : (unit -> unit) -> unit
val register_epilogue : (unit -> unit) -> string -> unit

@ -132,10 +132,14 @@ let add_profile_to_pom_in_directory dir =
let infer_pom_path = dir ^/ "pom.xml.infer" in
add_infer_profile maven_pom_path infer_pom_path;
Unix.rename ~src:maven_pom_path ~dst:saved_pom_path;
Utils.register_epilogue (fun () -> Unix.rename ~src:saved_pom_path ~dst:maven_pom_path);
Utils.register_epilogue
(fun () -> Unix.rename ~src:saved_pom_path ~dst:maven_pom_path)
"restoring Maven's pom.xml to its original state";
Unix.rename ~src:infer_pom_path ~dst:maven_pom_path;
if Config.debug_mode || Config.stats_mode then
Utils.register_epilogue (fun () -> Unix.rename ~src:maven_pom_path ~dst:infer_pom_path)
Utils.register_epilogue
(fun () -> Unix.rename ~src:maven_pom_path ~dst:infer_pom_path)
"saving infer's pom.xml"
let capture ~prog ~args =
while not (List.is_empty !pom_worklist); do

Loading…
Cancel
Save