Skip to content

GetTask and SetTask fail with an unrelated TypeError on a non-array input #22

Description

@njoubert-cleverage

Description

GetTask and SetTask only accept an array (or null) input, which is merged over their options. Any other non-empty input (typically a string output by a previous task) is not reported: AbstractCacheTask::getMergedOptions() passes it to array_merge() and the task fails with a \TypeError unrelated to the task.

Reproduction

demo.cache.get_invalid_input in process-bundle-demo:

clever_age_process:
    configurations:
        demo.cache.get_invalid_input:
            tasks:
                sku:
                    service: '@CleverAge\ProcessBundle\Task\ConstantOutputTask'
                    options:
                        output: 'key1'
                    outputs: [get]
                get:
                    service: '@CleverAge\CacheProcessBundle\Task\GetTask'
                    options:
                        adapter: 'memory'
                        key: '' # Overridden by the input
                    outputs: [debug]
                debug:
                    service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'
$ bin/console cleverage:process:execute demo.cache.get_invalid_input
In AbstractCacheTask.php line 52:
  array_merge(): Argument #2 must be of type array, string given

Same with SetTask.

Expected: an explicit \UnexpectedValueException, e.g. GetTask expects an array or null input, string given.

Tested on main (f5e8bb2), cleverage/process-bundle 5.1, PHP 8.5, Symfony 7.4.

Proposed fix

Check the input type in AbstractCacheTask::getMergedOptions() and throw an \UnexpectedValueException giving the task and the received type. Update the "Accepted inputs" section of get_task.md and set_task.md.

Requirements

  • Documentation updates
    • Reference
    • Changelog
  • Unit tests

Breaking changes

None: these inputs already make the task fail, only the exception changes.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions