Skip to content

Replace bare except clause with specific exception handling#118

Draft
Copilot wants to merge 2 commits into
refactor_modelsfrom
copilot/sub-pr-116-again
Draft

Replace bare except clause with specific exception handling#118
Copilot wants to merge 2 commits into
refactor_modelsfrom
copilot/sub-pr-116-again

Conversation

Copilot AI commented Dec 7, 2025

Copy link
Copy Markdown

Addresses code review feedback on PR #116 regarding a bare except: clause that silently catches all exceptions without explanation.

Changes:

  • Replace except: with except (TradeMatch.DoesNotExist, AttributeError): to catch only expected exceptions
  • Add explanatory comment documenting the fallback behavior

Before:

try:
    trade_match = TradeMatch.objects.get(pk=match_id)
    timetable_slug = trade_match.request_1.offered_allocation.timetable.slug
except:
    pass

After:

try:
    trade_match = TradeMatch.objects.get(pk=match_id)
    timetable_slug = trade_match.request_1.offered_allocation.timetable.slug
except (TradeMatch.DoesNotExist, AttributeError):
    # Silently ignore if trade match doesn't exist or lacks required attributes
    # We'll fall back to redirecting to '/' instead
    pass

This prevents inadvertently catching system-critical exceptions while making the code's intent explicit.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: Foosec <31885466+Foosec@users.noreply.github.com>
Copilot AI changed the title [WIP] Add changes to address review comments on model refactoring Replace bare except clause with specific exception handling Dec 7, 2025
Copilot AI requested a review from Foosec December 7, 2025 17:09
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.

2 participants