Skip to content

Commit

Permalink
Give better error messages for failing to parse a spec
Browse files Browse the repository at this point in the history
Call make_specs() explicitly and handle exceptions from it in order to
show the appropriate error message instead of letting argparse call it
implicitly. As mentioned in that module documentation:

> In general, the type keyword is a convenience that should only be used
> for simple conversions that can only raise one of the three supported
> exceptions. Anything with more interesting error-handling or resource
> management should be done downstream after the arguments are parsed.

And this is exactly what this commit does.

Closes #117.
  • Loading branch information
vadz committed Nov 7, 2024
1 parent 6decccb commit a45e119
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions abi3audit/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def main() -> None:
)
parser.add_argument(
"specs",
type=make_specs,
metavar="SPEC",
nargs="+",
help="the files or other dependency specs to scan",
Expand Down Expand Up @@ -230,12 +229,20 @@ def main() -> None:
if args.debug:
logging.root.setLevel("DEBUG")

specs = []
for spec in args.specs:
try:
specs.extend(make_specs(spec))
except InvalidSpec as e:
console.log(f"[red]:thumbs_down: processing error: {e}")
sys.exit(1)

logger.debug(f"parsed arguments: {args}")

results = SpecResults()
all_passed = True
with status:
for spec in itertools.chain.from_iterable(args.specs):
for spec in specs:
status.update(f"auditing {spec}")
try:
extractor = spec._extractor()
Expand Down

0 comments on commit a45e119

Please sign in to comment.