Skip to content

Fix for Empty except#164

Merged
redreceipt merged 1 commit intomainfrom
finding-autofix-e59b7f55
Dec 24, 2025
Merged

Fix for Empty except#164
redreceipt merged 1 commit intomainfrom
finding-autofix-e59b7f55

Conversation

@redreceipt
Copy link
Member

General approach: avoid empty except blocks that silently ignore all errors. Either (a) document why the exception is being ignored with a clear comment, or (b) log the exception so it can be observed while keeping the current control flow and user‑visible behavior.

Best fix here: keep the existing behavior that invalid dates produce None for days_left / starts_in, but add a small amount of logging plus a comment. Since days_left and starts_in are already initialized to None before the try, we don’t need to change any assignment logic. We just need to replace pass with something like app.logger.warning(...) and add comments explaining that invalid dates are treated as “no date”. This preserves all existing functionality while satisfying the CodeQL rule.

Concrete changes in app.py:

  • In the team() view’s loop over cycle_projects, replace:
746:         if target:
747:             try:
748:                 target_dt = datetime.fromisoformat(target).date()
749:                 days_left = (target_dt - datetime.utcnow().date()).days
750:             except ValueError:
751:                 pass

with a commented and logged block:

746:         if target:
747:             try:
748:                 target_dt = datetime.fromisoformat(target).date()
749:                 days_left = (target_dt - datetime.utcnow().date()).days
750:             except ValueError:
751:                 # If the target date is malformed, treat it as missing but log it for debugging.
752:                 app.logger.warning("Invalid targetDate %r for project %r", target, proj.get("id"))
  • Similarly, replace the start except block:
752:         if start:
753:             try:
754:                 start_dt = datetime.fromisoformat(start).date()
755:                 starts_in = (start_dt - datetime.utcnow().date()).days
756:             except ValueError:
757:                 pass

with:

752:         if start:
753:             try:
754:                 start_dt = datetime.fromisoformat(start).date()
755:                 starts_in = (start_dt - datetime.utcnow().date()).days
756:             except ValueError:
757:                 # If the start date is malformed, treat it as missing but log it for debugging.
758:                 app.logger.warning("Invalid startDate %r for project %r", start, proj.get("id"))

No new imports are needed because app is already defined as a Flask application and provides logger.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@redreceipt redreceipt marked this pull request as ready for review December 24, 2025 05:21
@redreceipt redreceipt temporarily deployed to bug-board-finding-autof-ks7kpy December 24, 2025 05:21 Inactive
@redreceipt redreceipt merged commit ad483fe into main Dec 24, 2025
7 checks passed
@redreceipt redreceipt deleted the finding-autofix-e59b7f55 branch December 24, 2025 05:22
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.

1 participant