Skip to content

Commit 9928a50

Browse files
committed
fix: replace bare except with explicit Exception in pipes/advisory.py
Signed-off-by: samay2504 <samay.m2504@gmail.com>
1 parent 32d9724 commit 9928a50

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

vulnerabilities/pipes/advisory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def import_advisory(
456456
f"and scoring_elements: {severity.scoring_elements!r}",
457457
level=logging.DEBUG,
458458
)
459-
except:
459+
except Exception:
460460
if logger:
461461
logger(
462462
f"Failed to create VulnerabilitySeverity for: {severity} with error:\n{traceback_format_exc()}",
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_advisory():
15+
"""Test that advisory.py does not contain bare except clauses."""
16+
file_path = os.path.join(os.path.dirname(__file__), "..", "pipes", "advisory.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)