Skip to content

fix(lint): resolve the error-handling ruff findings in src - #196

Merged
vsn411 merged 7 commits into
secfoo-com:mainfrom
AyhamJo7:fix/src-error-handling-lint
Nov 26, 2026
Merged

vsn411 merged 7 commits into
secfoo-com:mainfrom
AyhamJo7:fix/src-error-handling-lint

Conversation

@AyhamJo7

Copy link
Copy Markdown
Contributor

Closes #168

Resolves the error-handling ruff findings in src/ that #168 lists. On 509bd9b ten of the fourteen remained; the mcp.py PLW1510s and the EXE001 were already gone.

Rule Where Change
S110 + BLE001 runner.py _try_cloud_sync, _try_osv_enrich the broad catch stays (their docstrings: a failure must never fail the local run), with a one-line reason, and logs at debug with exc_info=True instead of pass
BLE001 docext.py extract_text stays broad (the PDF/DOCX/PPTX parsers raise many types, and a bad file means ""), with a reason and a debug log
BLE001 web/templating.py active_run_count stays broad (a storage problem must not break page rendering), with a reason and a debug log
BLE001 + PLW1510 runner.py _git_head_commit passes check=False like _git_tree_dirty; the catch stays broad with a reason and a debug log
PYI034 storage/repository.py __enter__ returns Self, imported from typing_extensions under TYPE_CHECKING because the floor is Python 3.10
RUF046 web/dashboard_common.py drops the redundant int() around round()

Why _git_head_commit keeps a broad catch: I first narrowed it to (OSError, subprocess.SubprocessError, ValueError). That made 22 tests in tests/test_responsible_ai_end_to_end.py fail, because the conftest FakePopen has no __exit__, so subprocess.run raises TypeError there and only the broad catch absorbed it. Commit metadata is optional, so the broad catch with a log is the behaviour-preserving choice.

Tests

New tests/test_runner_best_effort.py:

  • _git_head_commit returns None with no git on PATH, and when git times out.
  • A failing _try_cloud_sync does not raise and logs cloud sync skipped for run … at debug.

With runner.py from 509bd9b the logging test fails (1 of 3, as expected: main passed silently) and the two fallback tests pass. With this change all 3 pass.

Checks

  • ruff check src scripts --select BLE001,S110,PLW1510,PYI034,RUF046,EXE001: no findings. ruff check on the five touched files and the new test: clean.
  • pytest tests: 2267 passed, 1 skipped, 5 failed. The 5 also fail on an untouched 509bd9b checkout in the same environment (Python 3.14): test_runtime_api.py::test_lines_that_used_to_500_are_skipped_and_the_rest_is_stored[deep-nesting], three test_activity_routes.py::test_architecture_activity_page_* and test_architecture_dashboard.py::test_dashboard_diagram_section_still_present_alongside_new_dashboard.
  • tests/test_responsible_ai_end_to_end.py, tests/test_docext.py and the new file: 40 passed.

Not in this PR: the other ruff findings in src/ (import order, UP045, unused noqa) and the tests/ findings in #194.

Best-effort catches that swallowed failures silently now log them at debug level and say in one line why they stay broad. subprocess.run in _git_head_commit passes check=False like its sibling, RunRepository.__enter__ returns Self, and the percentile index drops a redundant int(). Behaviour is unchanged; a new test pins the git fallbacks and the logged cloud-sync failure.

Closes #168
@AyhamJo7
AyhamJo7 requested a review from vsn411 as a code owner November 25, 2026 09:08
AyhamJo7 and others added 3 commits November 25, 2026 11:21
…system.py executable

Logging at debug level does not satisfy BLE001, so each broad catch that
stays keeps its reason and an explicit noqa. EXE001: the script has a
shebang, so give it the executable bit like check_pypi_version.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/secfoo/docext.py Fixed
CodeQL flagged the new debug line as log injection because it formatted the upload's suffix. Only .pdf/.docx/.pptx can reach it, but the traceback already names the parser, so the message drops the value.
@AyhamJo7

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up commits. Two more in 6dc1203:

  • 05e6c6d addresses the CodeQL log-injection alert on docext.py: the extraction debug line no longer formats the upload's suffix (only .pdf/.docx/.pptx could reach it, but the traceback already names the parser). New test test_a_failed_extraction_logs_nothing_from_the_file_name checks the record has no arguments; it failed before (args == (".pdf",)) and passes now.
  • Merged current main again. tests/test_runner_best_effort.py, test_docext.py, test_runner.py and test_responsible_ai_end_to_end.py: 73 passed.

vsn411 added a commit to Labu1/secfoo that referenced this pull request Nov 26, 2026
…used noqa, removesuffix)

- ruff check . --fix for I001, RUF100 and FURB188.
- Kept the reasons where an unused noqa was removed (S608, A002); the
  nosec B310 comments for bandit stay.
- F401 on sast_dashboard.SKILL_ID is a re-export used by
  routes/activities.py, so it keeps the import with a noqa instead of
  deleting it.
- tests/fixtures is excluded from ruff: those files are byte-exact inputs
  checked by SHA-256, so lint must not rewrite them.
- Left RunRepository.__enter__ to secfoo-com#196, which returns Self there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411

vsn411 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks, and welcome! The changes are solid. I pushed one small commit to your branch (e9331a8) so the issue's "Done when" check passes:

  • Logging at debug level doesn't satisfy ruff's BLE001, so each broad except you kept now carries # noqa: BLE001 next to your reason.
  • scripts/sync_design_system.py now has the executable bit (EXE001), matching check_pypi_version.py.

CI for first-time contributors waits for a maintainer to approve the run. We'll merge as soon as it's green.

@vsn411
vsn411 merged commit 5db1681 into secfoo-com:main Nov 26, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown

Leaderboard update

AyhamJo7 now has 3 points (rank #12). 22 more to reach Bronze.

Full leaderboard

vsn411 added a commit that referenced this pull request Nov 26, 2026
… regex flags) (#198)

* chore(lint): apply ruff's safe autofixes

Apply the mechanical, behavior-preserving fixes ruff reports so lint
can eventually block in CI (#114):

- UP045: Optional[X] -> X | None in cli.py and the assessments routes,
  dropping the now-unused typing.Optional imports
- FURB167: re.S -> re.DOTALL in the dashboard tests
- RUF022: sort __all__ in agents, skills and targets packages
- UP037: unquote the RunRepository.__enter__ return annotation

Only annotations, __all__ order and regex flag names change; there is
no behavior change.

Fixes #165.

* chore(lint): finish #165's safe autofixes (import order, unused noqa, removesuffix)

- ruff check . --fix for I001, RUF100 and FURB188.
- Kept the reasons where an unused noqa was removed (S608, A002); the
  nosec B310 comments for bandit stay.
- F401 on sast_dashboard.SKILL_ID is a re-export used by
  routes/activities.py, so it keeps the import with a noqa instead of
  deleting it.
- tests/fixtures is excluded from ruff: those files are byte-exact inputs
  checked by SHA-256, so lint must not rewrite them.
- Left RunRepository.__enter__ to #196, which returns Self there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: aitechnology <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lint: fix error-handling ruff findings in src/ (blind except, try/except/pass, subprocess check)

3 participants