Skip to content

Commit 60a1731

Browse files
committed
fix: replace bare except with explicit Exception in import_runner.py
1 parent 32d9724 commit 60a1731

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

vulnerabilities/import_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def process_inferences(inferences: List[Inference], advisory: Advisory, improver
219219
},
220220
)
221221
vulnerability.severities.add(vulnerability_severity)
222-
except:
222+
except Exception:
223223
logger.error(
224224
f"Failed to create VulnerabilitySeverity for: {severity} with error:\n{traceback_format_exc()}"
225225
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
import ast
11+
import os
12+
13+
14+
def test_no_bare_except_in_import_runner():
15+
"""Test that import_runner.py does not contain bare except clauses."""
16+
file_path = os.path.join(os.path.dirname(__file__), "..", "import_runner.py")
17+
with open(file_path, "r") as f:
18+
source = f.read()
19+
20+
tree = ast.parse(source)
21+
22+
bare_excepts = []
23+
for node in ast.walk(tree):
24+
if isinstance(node, ast.ExceptHandler):
25+
if node.type is None:
26+
bare_excepts.append(node.lineno)
27+
28+
assert len(bare_excepts) == 0, f"Found bare except clauses at lines: {bare_excepts}"

0 commit comments

Comments
 (0)