Skip to content

Fix CSV import file-handle error handling#20

Open
mlintangmz2765 wants to merge 1 commit into
mainfrom
codex/fix-all-bugs-0idp9k
Open

Fix CSV import file-handle error handling#20
mlintangmz2765 wants to merge 1 commit into
mainfrom
codex/fix-all-bugs-0idp9k

Conversation

@mlintangmz2765

Copy link
Copy Markdown
Owner

Motivation

  • Prevent runtime warnings or fatal errors when an uploaded CSV cannot be opened by guarding fopen() and returning with a clear error message.
  • Ensure the uploaded-file state and file handle are always cleaned up even when exceptions occur during import.
  • Remove an unused variable to keep the implementation cleaner.

Description

  • Add a guard after fopen($path, 'r') that sets an error message and returns early if the handle is false to avoid operating on an invalid resource.
  • Move fclose($handle) and $this->file_csv = null into a finally block so cleanup always runs whether the import succeeds or an exception is thrown.
  • Remove the unused $errors counter from the method.
  • Keep existing CSV parsing, date parsing, contact sync and Postcard creation logic unchanged.

Testing

  • Ran php -l app/Livewire/ImportPostcards.php which reported no syntax errors and confirmed the modified file is valid.
  • Attempted to run the test suite with php artisan test but 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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +33 to +37
if ($handle === false) {
$this->message = 'Import failed: unable to read uploaded file.';
$this->messageType = 'error';

return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant