Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion vulnerabilities/import_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def process_inferences(inferences: List[Inference], advisory: Advisory, improver
},
)
vulnerability.severities.add(vulnerability_severity)
except:
except Exception:
logger.error(
f"Failed to create VulnerabilitySeverity for: {severity} with error:\n{traceback_format_exc()}"
)
Expand Down
28 changes: 28 additions & 0 deletions vulnerabilities/tests/test_bare_except_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# VulnerableCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#

import ast
import os


def test_no_bare_except_in_import_runner():
"""Test that import_runner.py does not contain bare except clauses."""
file_path = os.path.join(os.path.dirname(__file__), "..", "import_runner.py")
with open(file_path, "r") as f:
source = f.read()

tree = ast.parse(source)

bare_excepts = []
for node in ast.walk(tree):
if isinstance(node, ast.ExceptHandler):
if node.type is None:
bare_excepts.append(node.lineno)

assert len(bare_excepts) == 0, f"Found bare except clauses at lines: {bare_excepts}"