From ac92e1329209a34ef489e87e0f5d834e5ed3c414 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 24 Jan 2018 08:52:28 -0800 Subject: [PATCH] [cleanup] delete useless `Driver.Infer_error` exception Summary: The custom exception does not appear to serve any purpose. Also refactor the complaining code to avoid duplication. Reviewed By: mbouaziz Differential Revision: D6784945 fbshipit-source-id: a2d969b --- infer/src/integration/Driver.ml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index bfa8e6dd2..27487cef4 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -169,20 +169,21 @@ let touch_start_file_unless_continue () = else if not Config.continue_capture then ( delete () ; create () ) -exception Infer_error of string - -let default_error_handling : Unix.Exit_or_signal.t -> unit = function +let command_error_handling ~always_die ~prog ~args = function | Ok _ -> () - | Error _ as status when Config.keep_going -> - (* Log error and proceed past the failure when keep going mode is on *) - L.external_error "%s" (Unix.Exit_or_signal.to_string_hum status) ; - () | Error _ as status -> - raise (Infer_error (Unix.Exit_or_signal.to_string_hum status)) + let log = + if not always_die && Config.keep_going then + (* Log error and proceed past the failure when keep going mode is on *) + L.external_error + else L.die InternalError + in + log "Error running '%s' %a:@\n %s" prog Pp.cli_args args + (Unix.Exit_or_signal.to_string_hum status) -let run_command ?(cleanup= default_error_handling) ~prog ~args () = +let run_command ~prog ~args ?(cleanup= command_error_handling ~always_die:false ~prog ~args) () = Unix.waitpid (Unix.fork_exec ~prog ~argv:(prog :: args) ()) |> fun status -> cleanup status ; @@ -309,10 +310,8 @@ let capture ~changed_files mode = when Int.equal exit_code Config.infer_py_argparse_error_exit_code -> (* swallow infer.py argument parsing error *) Config.print_usage_exit () - | Error _ as status -> - raise (Infer_error (Unix.Exit_or_signal.to_string_hum status)) - | Ok _ -> - ()) + | status -> + command_error_handling ~always_die:true ~prog:infer_py ~args status) () | XcodeXcpretty (prog, args) -> L.progress "Capturing using xcodebuild and xcpretty...@." ;