Skip to content

Handle StopIteration in extract_phones when CSV files are empty/missing#1961

Merged
ccostino merged 1 commit intomainfrom
2899-when-users-view-old-jobs-the-code-crashes-trying-to-read-deleted-csv-files-500-error
Sep 5, 2025
Merged

Handle StopIteration in extract_phones when CSV files are empty/missing#1961
ccostino merged 1 commit intomainfrom
2899-when-users-view-old-jobs-the-code-crashes-trying-to-read-deleted-csv-files-500-error

Conversation

@heyitsmebev
Copy link
Contributor

@heyitsmebev heyitsmebev commented Sep 5, 2025

Handle StopIteration in extract_phones when CSV files are empty/missing

When users view old jobs, the code crashes trying to read deleted CSV files.

17:35:14.970: [APP/PROC/WEB.1] {"name": "app", "levelname": "ERROR", "message": "", "pathname": "/home/vcap/app/app/errors.py", "lineno": 110, "exc_info": "Traceback (most recent call last):\n File "/home/vcap/deps/0/python/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request\n rv = self.dispatch_request()\n ^^^^^^^^^^^^^^^^^^^^^^^\n File "/home/vcap/deps/0/python/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request\n return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/home/vcap/deps/0/python/lib/python3.12/site-packages/newrelic/hooks/framework_flask.py", line 73, in nr_wrapper_handler\n return wrapped(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^\n File "/home/vcap/app/app/job/rest.py", line 82, in get_all_notifications_for_service_job\n phones = extract_phones(job, service_id, job_id)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/home/vcap/app/app/aws/s3.py", line 479, in extract_phones\n first_row = next(csv_reader)\n ^^^^^^^^^^^^^^^^\nStopIteration", "time": "2025-09-05T00:35:14", "requestId": "5916f9d4987e4ae3558c5b1d1dfd8001", "application": "app", "service_id": "notify-admin", "logType": "application"}

Copy link
Contributor

@ccostino ccostino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @heyitsmebev, nice catch! This should handle things much more gracefully! 🙂

@ccostino ccostino merged commit f245f27 into main Sep 5, 2025
7 checks passed
@ccostino ccostino deleted the 2899-when-users-view-old-jobs-the-code-crashes-trying-to-read-deleted-csv-files-500-error branch September 5, 2025 01:13
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.

When users view old jobs, the code crashes trying to read deleted CSV files. 500 error

2 participants