Skip to content

ProcessState::addErrorContextValue() raises a TypeError that hides the real problem (empty iterables, PropertySetterTask) #203

Description

@njoubert-cleverage

Description

ProcessState::addErrorContextValue() only accepts string|int|array values. When a task passes any other value (null, bool, float, object), a \TypeError is thrown and the real behaviour or error is lost:

  • Iterable tasks on an empty iterable (ConstantIterableOutputTask, InputIteratorTask, YamlReaderTask with {}/[], SplitJoinLineTask with no line to produce): AbstractIterableOutputTask::execute() always adds iterator_key before checking the iterator. On an empty iterator key() is null, so the process fails instead of skipping the task, as documented.
  • PropertySetterTask: when a value cannot be set, the task adds the value to the error context. If that value is a bool, float, null or object, the TypeError replaces the original exception (e.g. NoSuchPropertyException).

Reproduction

clever_age_process:
    configurations:
        demo.error_context.empty_iterable:
            tasks:
                iterate:
                    service: '@CleverAge\ProcessBundle\Task\ConstantIterableOutputTask'
                    options:
                        output: []
                    outputs: [debug]
                debug:
                    service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'

        demo.error_context.property_setter:
            tasks:
                entry:
                    service: '@CleverAge\ProcessBundle\Task\ConstantOutputTask'
                    options:
                        output:
                            name: Foo
                    outputs: [set]
                set:
                    service: '@CleverAge\ProcessBundle\Task\PropertySetterTask'
                    options:
                        values:
                            enabled: true # property path on an array: cannot be written
                    outputs: [debug]
                debug:
                    service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'
$ bin/console cleverage:process:execute demo.error_context.empty_iterable
CRITICAL  [cleverage_process_task] CleverAge\ProcessBundle\Model\ProcessState::addErrorContextValue(): Argument #2 ($value) must be of type array|string|int, null given, called in /var/www/vendor/cleverage/process-bundle/src/Task/AbstractIterableOutputTask.php on line 33

$ bin/console cleverage:process:execute demo.error_context.property_setter
CRITICAL  [cleverage_process_task] CleverAge\ProcessBundle\Model\ProcessState::addErrorContextValue(): Argument #2 ($value) must be of type array|string|int, true given, called in /var/www/vendor/cleverage/process-bundle/src/Task/PropertySetterTask.php on line 42 ["property" => "enabled"]

Expected: the first process succeeds with no output, the second one reports Cannot write property "enabled" to an array. Maybe you should write the property path as "[enabled]" instead?. Tested on main (c1a2804), PHP 8.5, Symfony 7.4.

Cause

Proposed fix

  • Widen the $value parameter of ProcessState::addErrorContextValue() to mixed.
  • In AbstractIterableOutputTask::execute(), add iterator_key only when the iterator is valid: an empty iterable then produces no output and the task is skipped.
  • Update the reference documentation (property_setter_task.md, yaml_reader_task.md, split_join_line_task.md, 03-custom_tasks.md), add unit tests.

Requirements

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

Breaking changes

None for callers. Widening a parameter type is backward compatible, except for a subclass of ProcessState overriding addErrorContextValue() with the old signature (it must widen $value to mixed).

Activity

  1. added 2 commits that reference this issue on Sep 28, 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