Skip to content

Commit 0add05d

Browse files
jvillardFacebook Github Bot 5
authored andcommitted
do not print infer.py usage message on wrong arguments
Summary: On wrong arguments (or on no arguments at all), `infer` would spew the error message of `infer.py`, which makes no sense. Make the python code swallow error messages and exit with a special code on errors coming from command line parsing so that the OCaml side is in charge of printing usage messages. Reviewed By: cristianoc Differential Revision: D3731594 fbshipit-source-id: fe49cda
1 parent 145cb74 commit 0add05d

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

infer/lib/python/infer.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,23 @@ def split_args_to_parse():
7878
return (sys_argv[1:dd_index], cmd_raw)
7979

8080

81+
class FailSilentlyArgumentParser(argparse.ArgumentParser):
82+
'''We want to leave the handling of printing usage messages to the
83+
OCaml code. To do so, swallow error messages from ArgumentParser
84+
and exit with a special error code (101) that infer.ml looks for.
85+
'''
86+
87+
def error(self, message):
88+
utils.stderr(message)
89+
utils.stderr('')
90+
exit(22) # in sync with infer.ml
91+
92+
def print_help(self, file=None):
93+
exit(22) # in sync with infer.ml
94+
95+
8196
def create_argparser(parents=[]):
82-
parser = argparse.ArgumentParser(
97+
parser = FailSilentlyArgumentParser(
8398
parents=[analyze.infer_parser] + parents,
8499
add_help=False,
85100
formatter_class=argparse.RawDescriptionHelpFormatter,

infer/src/backend/infer.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ let () =
104104
) in
105105
let pid = Unix.create_process args_py.(0) args_py Unix.stdin Unix.stdout Unix.stderr in
106106
let _, status = Unix.waitpid [] pid in
107+
if status = Unix.WEXITED 22 then
108+
(* swallow infer.py argument parsing error *)
109+
Config.print_usage_exit ();
107110
(* collect crashcontext summaries *)
108111
let analysis_is_crashcontext = match Config.analyzer with
109112
| Some Crashcontext -> true

0 commit comments

Comments
 (0)