Skip to content

CsvWriterTask: a non-array input throws a TypeError when headers is null, and the task cannot run again after finalize() #241

Closed

Description

@njoubert-cleverage

Description

CsvWriterTask fails with a raw TypeError on a non-array input when headers is null (default), instead of the documented \UnexpectedValueException('Input value is not an array') thrown when headers is set.

Secondary point: the task cannot be executed again after finalize(), because $this->csv is closed but not reset. This does not happen through the ProcessManager (task services are not shared, a new instance is used for each run), but it is inconsistent with CsvReaderTask, which resets it since #208.

Reproduction

write:
    service: '@CleverAge\ProcessBundle\Task\File\Csv\CsvWriterTask'
    options:
        file_path: '/tmp/out.csv'

With the input 'foo':

TypeError: array_keys(): Argument #1 ($array) must be of type array, string given

Same task with headers: [a]: UnexpectedValueException: Input value is not an array (expected behaviour).

Second point: calling initialize(), execute(), proceed(), finalize() twice on the same instance throws RuntimeException: CSV file '/tmp/out.csv' was closed earlier on the second execute().

Reproduced on main (ad31c1f), PHP 8.5, Symfony 8.1, by calling the task / transformer directly. Found while adding the missing tests of #197.

Cause

Proposed fix

Validate the input before reading its keys in getHeaders() (throw the same \UnexpectedValueException), and reset $this->csv to null in AbstractCsvResourceTask::finalize(). Add tests.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None: both cases currently throw.

Activity

  1. added 2 commits that reference this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions