Skip to content

Commit

Permalink
Improve error message when .so file without .abi3. in it is speci…
Browse files Browse the repository at this point in the history
…fied (#118)

Co-authored-by: William Woodruff <[email protected]>
  • Loading branch information
vadz and woodruffw authored Nov 7, 2024
1 parent a9c608a commit c4290c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions abi3audit/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from __future__ import annotations

import argparse
import itertools
import json
import logging
import os
Expand All @@ -20,6 +19,7 @@
from abi3audit._audit import AuditError, AuditResult, audit
from abi3audit._extract import (
Extractor,
ExtractorError,
InvalidSpec,
PyPISpec,
SharedObjectSpec,
Expand Down Expand Up @@ -177,7 +177,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 @@ -229,16 +228,24 @@ 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()
except InvalidSpec as e:
except ExtractorError as e:
console.log(f"[red]:thumbs_down: processing error: {e}")
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion abi3audit/_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def make_specs(val: str) -> list[Spec]:
# audited (e.g. via an abi3 wheel), but not directly (since
# without a tag here we don't know if it's abi3 at all).
if ".abi3." not in val:
raise InvalidSpec(f"'{val}' looks like a shared object but is not tagged as abi3")
raise InvalidSpec(f"'{val}' must contain '.abi3.' to be recognized as a shared object")
return [SharedObjectSpec(val)]
elif re.match(_DISTRIBUTION_NAME_RE, val, re.IGNORECASE):
return [PyPISpec(val)]
Expand Down
2 changes: 1 addition & 1 deletion test/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_make_spec():
assert make_specs("foo") == [PyPISpec("foo")]

# Shared objects need to be tagged with `.abi3`.
with pytest.raises(InvalidSpec):
with pytest.raises(InvalidSpec, match="'foo.so' must contain '.abi3.'"):
make_specs("foo.so")

# Anything that doesn't look like a wheel, shared object, or PyPI package fails.
Expand Down

0 comments on commit c4290c6

Please sign in to comment.