From e006e57bfaa4b9f1755348730fb227ab01bb6f07 Mon Sep 17 00:00:00 2001 From: bhoomi-bombom Date: Sat, 1 Nov 2025 15:57:51 +0530 Subject: [PATCH] Replace assert statements with proper error handling in non-test files Signed-off-by: bhoomi-bombom --- src/attributecode/attrib.py | 12 +++++++++--- src/attributecode/util.py | 11 +++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/attributecode/attrib.py b/src/attributecode/attrib.py index b22c6d93..626e309f 100644 --- a/src/attributecode/attrib.py +++ b/src/attributecode/attrib.py @@ -193,9 +193,15 @@ def generate_sctk_input(abouts, min_license_score, license_dict): for key in lic_key: lic_name.append(license_dict[key][0]) lic_score = about.license_score.value - assert len(lic_key) == len(lic_name) - assert len(lic_key) == len(lic_score) - + len_lic_key = len(lic_key) + if len_lic_key != len(lic_name): + raise ValueError( + f"Mismatch between lengths: lic_key ({len_lic_key}) vs lic_name ({len(lic_name)})" + ) + if len_lic_key != len(lic_score): + raise ValueError( + f"Mismatch between lengths: lic_key ({len_lic_key}) vs lic_score ({len(lic_score)})" + ) lic_key_expression = about.license_key_expression.value if lic_key_expression: updated_lic_key_expression = [] diff --git a/src/attributecode/util.py b/src/attributecode/util.py index 5f398d7d..c78f44cd 100644 --- a/src/attributecode/util.py +++ b/src/attributecode/util.py @@ -167,7 +167,9 @@ def get_locations(location): """ location = add_unc(location) location = get_absolute(location) - assert os.path.exists(location) + if not os.path.exists(location): + raise FileNotFoundError(f"Expected path does not exist: {location}") + if os.path.isfile(location): yield location @@ -283,9 +285,10 @@ def get_relative_path(base_loc, full_loc): base = norm(base_loc) path = norm(full_loc) - assert path.startswith(base), ( - "Cannot compute relative path: %(path)r does not start with %(base)r" % locals() - ) + if not path.startswith(base): + raise ValueError( + f"Cannot compute relative path: {path!r} does not start with {base!r}" + ) base_name = resource_name(base) no_dir = base == base_name same_loc = base == path