Skip to content

fix: handle unknown email gracefully in showSummary#11

Merged
SiRipo92 merged 5 commits intoQAfrom
fix/login-unknown-email-crash
Mar 13, 2026
Merged

fix: handle unknown email gracefully in showSummary#11
SiRipo92 merged 5 commits intoQAfrom
fix/login-unknown-email-crash

Conversation

@SiRipo92
Copy link
Owner

Closes #2

Problem

When a user submitted an email not found in clubs.json, the app crashed
with an IndexError 500. The [0] index was called on an empty list with
no error handling in place.

Root Cause

list comprehension + [0] assumed a match would always be found:
club = [club for club in clubs if club['email'] == request.form['email']][0]

Fix

Replaced [0] list indexing with next() and a None default, allowing the
absent case to be handled explicitly rather than crashing:
club = next((club for club in clubs if club['email'] == request.form['email']), None)

Added if not club guard to flash an error message and redirect back to
index.html without crashing.

Updated index.html and welcome.html to display flash messages.

Tests

  • SAD PATH: unknown email returns 200 + error message
  • HAPPY PATH: valid email loads welcome/summary page
  • EDGE CASE: empty email submission handled gracefully

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