Skip to content

Ruff: Preparation for TRY301 #12738

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

Open
wants to merge 1 commit into
base: bugfix
Choose a base branch
from
Open
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
23 changes: 11 additions & 12 deletions dojo/tools/blackduck_component_risk/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def _process_zipfile(self, report: Path) -> (dict, dict, dict):
"""
components = {}
source = {}
try:
with zipfile.ZipFile(str(report)) as zipf:
c_file = False
s_file = False
with zipfile.ZipFile(str(report)) as zipf:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if an exception occurs here as it will no longer be caught

c_file = False
s_file = False
try:
for full_file_name in zipf.namelist():
# Just in case the word component or security is in the name of
# zip file, best to ignore it.
Expand All @@ -62,14 +62,13 @@ def _process_zipfile(self, report: Path) -> (dict, dict, dict):
elif "source" in file_name:
with io.TextIOWrapper(zipf.open(full_file_name), encoding="utf-8") as f:
source = self.__get_source(f)
# Raise exception to error-out if the zip is missing either of
# these files.
if not (c_file and s_file):
msg = "Zip file missing needed files!"
raise Exception(msg)

except Exception:
logger.exception("Could not process zip file")
except Exception:
logger.exception("Could not process zip file")
# Raise exception to error-out if the zip is missing either of
# these files.
if not (c_file and s_file):
msg = "Zip file missing needed files!"
raise Exception(msg)

return components, security_issues, source

Expand Down