Fix CSV import file-handle error handling#19
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e5fdb49c6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| $this->message = 'Import failed: unable to read uploaded file.'; | ||
| $this->messageType = 'error'; | ||
|
|
||
| return; |
There was a problem hiding this comment.
Clear uploaded file state before early return
If fopen() fails, this new early return exits before the cleanup in finally, so $this->file_csv is never reset on this error path. In Livewire, keeping the file-bound property populated after a failed upload can block straightforward retry flows (especially re-selecting the same file), causing repeated import failures until the component is refreshed. Route this branch through shared cleanup or explicitly reset $this->file_csv before returning.
Useful? React with 👍 / 👎.
Motivation
fopen()and returning with a clear error message.Description
fopen($path, 'r')that sets an error message and returns early if the handle isfalseto avoid operating on an invalid resource.fclose($handle)and$this->file_csv = nullinto afinallyblock so cleanup always runs whether the import succeeds or an exception is thrown.$errorscounter from the method.Testing
php -l app/Livewire/ImportPostcards.phpwhich reported no syntax errors and confirmed the modified file is valid.php artisan testbut the environment could not install Composer dependencies due to network/GitHub access errors, so the full automated test suite could not be executed.Codex Task