diff --git a/src/macaron/database/table_definitions.py b/src/macaron/database/table_definitions.py index 7b173fad4..035df8f31 100644 --- a/src/macaron/database/table_definitions.py +++ b/src/macaron/database/table_definitions.py @@ -103,7 +103,7 @@ class PackageURLMixin: name: Mapped[str] = mapped_column(String(100), nullable=False, comment="Name of the package.") #: Version of the package. - version: Mapped[str] | None = mapped_column(String(100), nullable=True, comment="Version of the package.") + version: Mapped[str | None] = mapped_column(String(100), nullable=True, comment="Version of the package.") #: Extra qualifying data for a package such as the name of an OS. qualifiers: Mapped[str] = mapped_column( diff --git a/src/macaron/malware_analyzer/pypi_heuristics/metadata/wheel_presence.py b/src/macaron/malware_analyzer/pypi_heuristics/metadata/wheel_presence.py index 8610948d3..7bd2a9ddb 100644 --- a/src/macaron/malware_analyzer/pypi_heuristics/metadata/wheel_presence.py +++ b/src/macaron/malware_analyzer/pypi_heuristics/metadata/wheel_presence.py @@ -51,22 +51,32 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes """ releases = pypi_package_json.get_releases() if releases is None: # no release information - raise HeuristicAnalyzerValueError("There is no information for any release of this package.") + error_msg = "There is no information for any release of this package." + logger.debug(error_msg) + raise HeuristicAnalyzerValueError(error_msg) version = pypi_package_json.component.version if version is None: # check latest release version version = pypi_package_json.get_latest_version() + if version is None: - raise HeuristicAnalyzerValueError("There is no latest version of this package.") + error_msg = "There is no latest version of this package." + logger.debug(error_msg) + raise HeuristicAnalyzerValueError(error_msg) release_files: list[JsonType] = [] wheel_present: bool = False - for release_metadata in releases[version]: - if release_metadata["packagetype"] == self.WHEEL: - wheel_present = True + try: + for release_metadata in releases[version]: + if release_metadata["packagetype"] == self.WHEEL: + wheel_present = True - release_files.append(release_metadata["filename"]) + release_files.append(release_metadata["filename"]) + except KeyError as error: + error_msg = f"The version {version} is not available as a release." + logger.debug(error_msg) + raise HeuristicAnalyzerValueError(error_msg) from error if wheel_present: return HeuristicResult.PASS, {version: release_files}