Fix CSV import file-handle error handling#20
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1584f5052
ℹ️ 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".
| if ($handle === false) { | ||
| $this->message = 'Import failed: unable to read uploaded file.'; | ||
| $this->messageType = 'error'; | ||
|
|
||
| return; |
There was a problem hiding this comment.
Reset upload state before returning on open failure
When fopen() fails, this early return exits before the finally block that clears $this->file_csv, so the component keeps a stale TemporaryUploadedFile reference after an error. In ImportPostcards, the UI state (selected filename and submit-button enabled state) is driven by $file_csv (resources/views/livewire/import-postcards.blade.php), so users can get stuck repeatedly submitting the same unreadable upload unless they manually reselect a file; this regresses the cleanup guarantee added elsewhere in this commit.
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