Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when .so file without .abi3. in it is specified #118

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading