Skip to content

Commit

Permalink
do not print infer.py usage message on wrong arguments
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jvillard authored and Facebook Github Bot 5 committed Aug 18, 2016
1 parent 145cb74 commit 0add05d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion infer/lib/python/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,23 @@ def split_args_to_parse():
return (sys_argv[1:dd_index], cmd_raw)


class FailSilentlyArgumentParser(argparse.ArgumentParser):
'''We want to leave the handling of printing usage messages to the
OCaml code. To do so, swallow error messages from ArgumentParser
and exit with a special error code (101) that infer.ml looks for.
'''

def error(self, message):
utils.stderr(message)
utils.stderr('')
exit(22) # in sync with infer.ml

def print_help(self, file=None):
exit(22) # in sync with infer.ml


def create_argparser(parents=[]):
parser = argparse.ArgumentParser(
parser = FailSilentlyArgumentParser(
parents=[analyze.infer_parser] + parents,
add_help=False,
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down
3 changes: 3 additions & 0 deletions infer/src/backend/infer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ let () =
) in
let pid = Unix.create_process args_py.(0) args_py Unix.stdin Unix.stdout Unix.stderr in
let _, status = Unix.waitpid [] pid in
if status = Unix.WEXITED 22 then
(* swallow infer.py argument parsing error *)
Config.print_usage_exit ();
(* collect crashcontext summaries *)
let analysis_is_crashcontext = match Config.analyzer with
| Some Crashcontext -> true
Expand Down

0 comments on commit 0add05d

Please sign in to comment.