Skip to content

Commit 0ad662c

Browse files
tamilarifmoessbauer
authored andcommitted
refactor: abort if neither source nor binary pkg
Either return the entry or raise an error if the package is neither a source nor a binary package (instead of returning nothing). Signed-off-by: Tamino Larisch <[email protected]>
1 parent 9958f02 commit 0ad662c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/debsbom/generate/cdx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ def cdx_package_repr(
7676
entry.description = package.description
7777
entry.properties.add(cdx_model.Property(name="section", value=package.section))
7878
logger.debug(f"Created binary component: {entry}")
79-
return entry
8079
elif package.is_source():
8180
logger.debug(f"Created source component: {entry}")
82-
return entry
81+
else:
82+
raise RuntimeError(f"The package {package} is neither a source nor a binary package")
83+
return entry
8384

8485

8586
def make_distro_component(

src/debsbom/generate/spdx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def spdx_package_repr(package: Package, vendor: str = "debian") -> spdx_package.
145145
url = url._replace(netloc=url.netloc.lower())
146146
spdx_pkg.homepage = urlunparse(url)
147147
logger.debug(f"Created binary package: {spdx_pkg}")
148-
return spdx_pkg
149148
elif package.is_source():
150149
spdx_pkg = spdx_package.Package(
151150
spdx_id=Reference.make_from_pkg(package).as_str(SBOMType.SPDX),
@@ -171,7 +170,9 @@ def spdx_package_repr(package: Package, vendor: str = "debian") -> spdx_package.
171170
primary_package_purpose=spdx_package.PackagePurpose.SOURCE,
172171
)
173172
logger.debug(f"Created source package: {spdx_pkg}")
174-
return spdx_pkg
173+
else:
174+
raise RuntimeError(f"The package {package} is neither a source nor a binary package")
175+
return spdx_pkg
175176

176177

177178
def spdx_bom(

0 commit comments

Comments
 (0)