Skip to content

Commit 8efbb4e

Browse files
grievejiafacebook-github-bot
authored andcommitted
Share ExitStatus.t and on_exception between new check and new infer command
Reviewed By: dkgi Differential Revision: D30466704 fbshipit-source-id: aec6a1ad89d93b92f655af7b9a52796673a1648c
1 parent 0562a8b commit 8efbb4e

File tree

3 files changed

+19
-43
lines changed

3 files changed

+19
-43
lines changed

source/command/newCheckCommand.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ let run_check check_configuration =
182182
Lwt.return ExitStatus.Ok)
183183

184184

185-
let on_check_exception = function
185+
let on_exception = function
186186
| Buck.Raw.BuckError { arguments; description; exit_code } ->
187187
Log.error
188188
"Cannot build the project: %s. To reproduce this error, run `%s`."
@@ -241,7 +241,7 @@ let run_check configuration_file =
241241
~memory_profiling_output
242242
();
243243

244-
Lwt_main.run (Lwt.catch (fun () -> run_check check_configuration) on_check_exception)
244+
Lwt_main.run (Lwt.catch (fun () -> run_check check_configuration) on_exception)
245245
in
246246
Statistics.flush ();
247247
exit (ExitStatus.exit_code exit_status)

source/command/newCheckCommand.mli

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
open Core
99

10+
module ExitStatus : sig
11+
type t =
12+
| Ok
13+
| PyreError
14+
| BuckInternalError
15+
| BuckUserError
16+
[@@deriving sexp, compare, hash]
17+
18+
val exit_code : t -> int
19+
end
20+
1021
module CheckConfiguration : sig
1122
type t = {
1223
base: NewCommandStartup.BaseConfiguration.t;
@@ -20,3 +31,5 @@ module CheckConfiguration : sig
2031
end
2132

2233
val command : Command.t
34+
35+
val on_exception : exn -> ExitStatus.t Lwt.t

source/command/newInferCommand.ml

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,8 @@
88
open Core
99
module Path = PyrePath
1010

11-
module ExitStatus = struct
12-
type t =
13-
| Ok
14-
| PyreError
15-
| BuckInternalError
16-
| BuckUserError
17-
[@@deriving sexp, compare, hash]
18-
19-
let exit_code = function
20-
| Ok -> 0
21-
| PyreError -> 1
22-
| BuckInternalError -> 2
23-
| BuckUserError -> 3
24-
end
11+
(* Infer command uses the same exit code scheme as check command. *)
12+
module ExitStatus = NewCheckCommand.ExitStatus
2513

2614
module InferMode = struct
2715
type t =
@@ -231,32 +219,6 @@ let run_infer infer_configuration =
231219
| InferMode.Interprocedural -> run_infer_interprocedural ~configuration ~build_system ())
232220

233221

234-
let on_infer_exception = function
235-
| Buck.Raw.BuckError { arguments; description; exit_code } ->
236-
Log.error
237-
"Cannot build the project: %s. To reproduce this error, run `%s`."
238-
description
239-
(Buck.Raw.ArgumentList.to_buck_command arguments);
240-
let exit_status =
241-
match exit_code with
242-
| Some exit_code when exit_code < 10 -> ExitStatus.BuckUserError
243-
| _ -> ExitStatus.BuckInternalError
244-
in
245-
Lwt.return exit_status
246-
| Buck.Builder.JsonError message ->
247-
Log.error "Cannot build the project because Buck returns malformed JSON: %s" message;
248-
Lwt.return ExitStatus.BuckUserError
249-
| Buck.Builder.LinkTreeConstructionError message ->
250-
Log.error
251-
"Cannot build the project because Pyre encounters a fatal error while constructing a link \
252-
tree: %s"
253-
message;
254-
Lwt.return ExitStatus.BuckUserError
255-
| _ as exn ->
256-
Log.error "Pyre encountered an internal exception: %s" (Exn.to_string exn);
257-
Lwt.return ExitStatus.PyreError
258-
259-
260222
let run_infer configuration_file =
261223
let exit_status =
262224
match
@@ -289,7 +251,8 @@ let run_infer configuration_file =
289251
~memory_profiling_output
290252
();
291253

292-
Lwt_main.run (Lwt.catch (fun () -> run_infer infer_configuration) on_infer_exception)
254+
Lwt_main.run
255+
(Lwt.catch (fun () -> run_infer infer_configuration) NewCheckCommand.on_exception)
293256
in
294257
Statistics.flush ();
295258
exit (ExitStatus.exit_code exit_status)

0 commit comments

Comments
 (0)