Catch argparse type errors (#911)

Catch argparse argument type errors and display them in a simplified fashion.

As an example, this is how the output is rendered.
```
❯ onefuzz template libfuzzer basic --target_env  ASAN_OPTIONS=allocator_may_return_null=1 a a a linux
unable to parse arguments: unable to parse value as a key=value pair: 'a'   
❯
```

Note, this builds upon #910.
This commit is contained in:
bmc-msft
2021-05-24 12:04:59 -04:00
committed by GitHub
parent 2c9a73dad9
commit db4c03ea56

View File

@ -524,7 +524,11 @@ def execute_api(api: Any, api_types: List[Any], version: str) -> int:
builder = Builder(api_types) builder = Builder(api_types)
builder.add_version(version) builder.add_version(version)
builder.parse_api(api) builder.parse_api(api)
try:
args = builder.parse_args() args = builder.parse_args()
except argparse.ArgumentTypeError as err:
LOGGER.error("unable to parse arguments: %s", err)
return 1
if args.verbose == 0: if args.verbose == 0:
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)