|
24 | 24 |
|
25 | 25 | from macaron.database.database_manager import ORMBase
|
26 | 26 | from macaron.database.rfc3339_datetime import RFC3339DateTime
|
27 |
| -from macaron.errors import CUEExpectationError, CUERuntimeError |
| 27 | +from macaron.errors import CUEExpectationError, CUERuntimeError, InvalidPURLError |
28 | 28 | from macaron.slsa_analyzer.provenance.expectations.cue import cue_validator
|
29 | 29 | from macaron.slsa_analyzer.provenance.expectations.expectation import Expectation
|
30 | 30 | from macaron.slsa_analyzer.slsa_req import ReqName
|
@@ -172,9 +172,21 @@ def __init__(self, purl: str, analysis: Analysis, repository: "Repository | None
|
172 | 172 | The corresponding analysis.
|
173 | 173 | repository: Repository | None
|
174 | 174 | The corresponding repository.
|
| 175 | +
|
| 176 | + Raises |
| 177 | + ------ |
| 178 | + InvalidPURLError |
| 179 | + If the PURL provided from the user is invalid. |
175 | 180 | """
|
176 |
| - purl_parts = PackageURL.from_string(purl) |
177 |
| - purl_kwargs = purl_parts.to_dict() |
| 181 | + try: |
| 182 | + purl_parts = PackageURL.from_string(purl) |
| 183 | + except ValueError as error: |
| 184 | + raise InvalidPURLError(f"The package url {purl} is not valid.") from error |
| 185 | + |
| 186 | + # We set ``encode=True`` to encode qualifiers as a normalized string because SQLite doesn't support ``dict`` type. |
| 187 | + # TODO: Explore the ``dbm`` or ``shelve`` packages to support dict type, which are part of the Python standard library. |
| 188 | + purl_kwargs = purl_parts.to_dict(encode=True) |
| 189 | + |
178 | 190 | super().__init__(purl=purl, analysis=analysis, repository=repository, **purl_kwargs)
|
179 | 191 |
|
180 | 192 | @property
|
|
0 commit comments