From 6d402a593d2424fac1d755c4a3664ec9a663384f Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Fri, 21 May 2021 10:01:43 -0400 Subject: [PATCH 1/2] explain key=value argument parsing failures --- src/cli/onefuzz/cli.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cli/onefuzz/cli.py b/src/cli/onefuzz/cli.py index 07edb5c682..a7025200b0 100644 --- a/src/cli/onefuzz/cli.py +++ b/src/cli/onefuzz/cli.py @@ -303,6 +303,13 @@ def __call__( ) -> None: if values is None: return + + for arg in values: + if "=" not in arg: + raise argparse.ArgumentTypeError( + "unable to parse value as a key=value pair: %s" % repr(arg) + ) + as_dict: Dict[str, str] = { key_arg(k): val_arg(v) for k, v in (x.split("=", 1) for x in values) } From cdd5e5c5262f44f59f28705f9d86bf2f1b0db0a9 Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Fri, 21 May 2021 10:07:37 -0400 Subject: [PATCH 2/2] catch argparse.ArgumentTypeError exceptions --- src/cli/onefuzz/cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cli/onefuzz/cli.py b/src/cli/onefuzz/cli.py index a7025200b0..cff5aa307e 100644 --- a/src/cli/onefuzz/cli.py +++ b/src/cli/onefuzz/cli.py @@ -524,7 +524,11 @@ def execute_api(api: Any, api_types: List[Any], version: str) -> int: builder = Builder(api_types) builder.add_version(version) builder.parse_api(api) - args = builder.parse_args() + try: + args = builder.parse_args() + except argparse.ArgumentTypeError as err: + LOGGER.error("unable to parse arguments: %s", err) + return 1 if args.verbose == 0: logging.basicConfig(level=logging.WARNING)