Skip to content

Commit be894d6

Browse files
committed
fix: graceful handling of purls without version
1 parent 7638a07 commit be894d6

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

complassist/_clearlydefined.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,27 @@ def get_clearlydefined_license_and_copyright_in_batches(
198198
"""
199199
# Create connections between purl <-> coordinates
200200
# It might happen that a coordinate describes more than one purl (e.g. SHAs for GitHub tags)
201-
purls_coordinates = {purl: purl2clearlydefined(purl) for purl in purls}
201+
purls_coordinates: dict[str, str] = {}
202+
for purl in purls:
203+
try:
204+
coordinates = purl2clearlydefined(purl)
205+
except (ValueError, SystemExit):
206+
coordinates = None
207+
if coordinates is None:
208+
logging.warning(
209+
"Could not convert purl %s to ClearlyDefined coordinates, skipping", purl
210+
)
211+
else:
212+
purls_coordinates[purl] = coordinates
213+
# Include skipped purls with empty data
214+
skipped_purls = set(purls) - set(purls_coordinates)
202215
# Request the CD API for the coordinates
203216
api_return = _cdapi_call(
204217
path="", method="POST", json_dict=list(purls_coordinates.values()), expand="-files"
205218
)
206219

207220
if api_return:
208-
result: dict[str, tuple[str, str]] = {}
221+
result: dict[str, tuple[str, str]] = dict.fromkeys(skipped_purls, ("", ""))
209222
for pkg_coordinates, cd_data in api_return.items():
210223
# Extract license and copyright data from the CD API return
211224
declared_license, copyrights = _extract_license_copyright(cd_data)

complassist/_sbom_enrich.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ def enrich_sbom_with_clearlydefined(
283283
else:
284284
for purl in all_purls:
285285
logging.info("Getting ClearlyDefined data for %s", purl)
286-
coordinates = purl2clearlydefined(purl)
286+
try:
287+
coordinates = purl2clearlydefined(purl)
288+
except (ValueError, SystemExit):
289+
coordinates = None
287290
if coordinates is None:
288291
logging.warning("Could not convert purl %s to ClearlyDefined coordinates", purl)
289292
clearlydefined_data[purl] = {"license": "", "copyright": ""}

0 commit comments

Comments
 (0)