Skip to content

Commit f443331

Browse files
authored
chore(codeql): document empty fallback catches
Add explanatory comments to intentional best-effort catches so empty-except fallbacks are auditable.
1 parent 9a67ad7 commit f443331

16 files changed

Lines changed: 49 additions & 0 deletions

src/analyzers/activity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def analyze(
138138
try:
139139
dates.append(datetime.fromisoformat(pub.replace("Z", "+00:00")))
140140
except (ValueError, TypeError):
141+
# Ignore malformed release timestamps when estimating cadence.
141142
pass
142143
if len(dates) >= 2:
143144
dates.sort()

src/analyzers/cicd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def _has_build_scripts(repo_path: Path) -> bool:
8989
if "build" in scripts or "test" in scripts:
9090
return True
9191
except (json.JSONDecodeError, OSError):
92+
# Malformed or unreadable package metadata means no script signal is detected.
9293
pass
9394

9495
# Makefile

src/analyzers/dependencies.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def cache_inputs_hash(
6363
pieces.append(fname.encode())
6464
pieces.append(fpath.read_bytes())
6565
except OSError:
66+
# Ignore unreadable dependency files in the cache fingerprint.
6667
pass
6768
if not pieces:
6869
return None
@@ -192,6 +193,7 @@ def _count_dependencies(repo_path: Path, manifests: list[str]) -> int | None:
192193
dev_deps = len(pkg.get("devDependencies", {}))
193194
return deps + dev_deps
194195
except (json.JSONDecodeError, OSError):
196+
# Unparseable package metadata falls through to other manifest types.
195197
pass
196198

197199
if "requirements.txt" in manifests:
@@ -205,6 +207,7 @@ def _count_dependencies(repo_path: Path, manifests: list[str]) -> int | None:
205207
and not line.strip().startswith("-")
206208
)
207209
except OSError:
210+
# Unreadable requirements files fall through to other manifest types.
208211
pass
209212

210213
if "Cargo.toml" in manifests:
@@ -223,6 +226,7 @@ def _count_dependencies(repo_path: Path, manifests: list[str]) -> int | None:
223226
count += 1
224227
return count
225228
except OSError:
229+
# Unreadable Cargo manifests fall through to other manifest types.
226230
pass
227231

228232
if "go.mod" in manifests:
@@ -240,6 +244,7 @@ def _count_dependencies(repo_path: Path, manifests: list[str]) -> int | None:
240244
count += 1
241245
return count
242246
except OSError:
247+
# Unreadable Go modules fall through to other manifest types.
243248
pass
244249

245250
if "pyproject.toml" in manifests:
@@ -258,6 +263,7 @@ def _count_dependencies(repo_path: Path, manifests: list[str]) -> int | None:
258263
count += 1
259264
return count if count > 0 else None
260265
except OSError:
266+
# Unreadable pyproject metadata means no dependency count is available.
261267
pass
262268

263269
return None

src/analyzers/testing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def _detect_test_framework(repo_path: Path) -> str | None:
103103
if "cypress" in all_deps:
104104
return "cypress"
105105
except (json.JSONDecodeError, OSError):
106+
# Unreadable package metadata simply means no JS test runner was detected.
106107
pass
107108

108109
# Python — check pyproject.toml for pytest
@@ -115,6 +116,7 @@ def _detect_test_framework(repo_path: Path) -> str | None:
115116
if "unittest" in content:
116117
return "unittest"
117118
except OSError:
119+
# Unreadable project metadata simply means no Python test runner was detected.
118120
pass
119121

120122
# Python — check for pytest in requirements
@@ -126,6 +128,7 @@ def _detect_test_framework(repo_path: Path) -> str | None:
126128
if "pytest" in content:
127129
return "pytest"
128130
except OSError:
131+
# Unreadable requirements files are ignored during best-effort detection.
129132
pass
130133

131134
# Rust — check Cargo.toml for dev-dependencies
@@ -136,6 +139,7 @@ def _detect_test_framework(repo_path: Path) -> str | None:
136139
if "[dev-dependencies]" in content:
137140
return "cargo-test"
138141
except OSError:
142+
# Unreadable Cargo metadata simply means no Rust test runner was detected.
139143
pass
140144

141145
# Go — test files convention

src/briefing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ def _parse_suggestions_json(raw: str, top_repos: list[dict]) -> list[Suggestion]
388388
result.append(Suggestion(name=name, action=action))
389389
return result
390390
except (json.JSONDecodeError, IndexError, TypeError):
391+
# Fall back to regex extraction when the model response is not valid JSON.
391392
pass
392393

393394
# Regex fallback: extract quoted strings

src/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def _gh_auth_token() -> str | None:
109109
if result.returncode == 0 and result.stdout.strip():
110110
return result.stdout.strip()
111111
except (FileNotFoundError, subprocess.TimeoutExpired):
112+
# Missing or slow gh CLI auth falls back to unauthenticated/public mode.
112113
pass
113114
return None
114115

@@ -3044,6 +3045,7 @@ def _run_list_initiatives_mode(args) -> None:
30443045
if name:
30453046
projects_by_name[name.lower()] = proj
30463047
except (OSError, ValueError):
3048+
# Initiative listing can proceed without portfolio-truth tier context.
30473049
pass
30483050

30493051
open_initiatives = [i for i in initiatives if i.closed_at is None]
@@ -3076,6 +3078,7 @@ def _run_list_initiatives_mode(args) -> None:
30763078
days_left = (date.fromisoformat(initiative.deadline) - date.today()).days
30773079
status_detail = f"at-risk (deadline ≤ {days_left}d)"
30783080
except ValueError:
3081+
# Malformed deadlines keep the generic at-risk label.
30793082
pass
30803083
elif status == "on-track":
30813084
status_detail = "on-track"
@@ -3598,6 +3601,7 @@ def _run_main_audit_cycle(args, config_inspection) -> None:
35983601
resumed_audits.append(_audit_from_dict(audit_dict))
35993602
resumed_names.add(audit_dict.get("metadata", {}).get("name", ""))
36003603
except Exception:
3604+
# Skip corrupt resume entries and continue with the rest.
36013605
pass
36023606
if resumed_audits:
36033607
print_info(f"Resumed {len(resumed_audits)} previously completed repo(s)")
@@ -4968,6 +4972,7 @@ def _fresh_run(repo_path, meta, conn=None):
49684972
try:
49694973
_warehouse_conn.close()
49704974
except Exception:
4975+
# Warehouse close failures are non-actionable during final cleanup.
49714976
pass
49724977
if _reconcile_diverged:
49734978
sys.exit(1)

src/cloner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def _git_askpass_env(token: str | None) -> Generator[dict[str, str] | None, None
5252
try:
5353
script_path.unlink()
5454
except OSError:
55+
# Temporary askpass cleanup is best-effort.
5556
pass
5657

5758

src/excel_workbook_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def set_defined_name(wb: Workbook, name: str, attr_text: str) -> None:
102102
try:
103103
del wb.defined_names[name]
104104
except KeyError:
105+
# The defined name may not exist yet.
105106
pass
106107
wb.defined_names.add(DefinedName(name, attr_text=attr_text))
107108

src/issue_creator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def create_audit_issues(
2727
skipped.append(repo_name)
2828
continue
2929
except Exception:
30+
# If issue listing fails, continue and let create_issue surface any hard error.
3031
pass
3132
actions = qw.get("actions", [])
3233
title = f"[Audit] {repo_name}: {actions[0] if actions else 'Improve audit score'}"

src/libyears.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def _parse_pip_deps(path: Path) -> list[tuple[str, str, str]]:
102102
if match:
103103
deps.append((match.group(1), match.group(2), "pypi"))
104104
except OSError:
105+
# Missing or unreadable requirements files have no parseable dependencies.
105106
pass
106107
return deps
107108

@@ -123,6 +124,7 @@ def _parse_cargo_deps(path: Path) -> list[tuple[str, str, str]]:
123124
if match:
124125
deps.append((match.group(1), match.group(2), "crates"))
125126
except OSError:
127+
# Missing or unreadable Cargo manifests have no parseable dependencies.
126128
pass
127129
return deps
128130

@@ -144,6 +146,7 @@ def _parse_pyproject_deps(path: Path) -> list[tuple[str, str, str]]:
144146
if match:
145147
deps.append((match.group(1), match.group(3), "pypi"))
146148
except OSError:
149+
# Missing or unreadable pyproject files have no parseable dependencies.
147150
pass
148151
return deps
149152

0 commit comments

Comments
 (0)