Skip to content

CommandRunnerTask always fails: all task options are passed to Process::setOptions() #192

Description

@Tmalboeuf-CA

Description

CommandRunnerTask cannot be used: every execution fails, whatever the command.

Reproduction

clever_age_process:
    configurations:
        demo.command_runner:
            tasks:
                run:
                    service: '@CleverAge\ProcessBundle\Task\Process\CommandRunnerTask'
                    options:
                        commandline: ['echo', 'hello']
                    outputs: [debug]
                debug:
                    service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'
$ bin/console cleverage:process:execute demo.command_runner
Starting process 'demo.command_runner'...
CRITICAL [cleverage_process_task] Invalid option "cwd" passed to "Symfony\Component\Process\Process::setOptions()".
Supported options are "blocking_pipes", "create_process_group", "create_new_console".

A string commandline (allowed by setAllowedTypes('commandline', ['string', 'array'])) fails even earlier:

Symfony\Component\Process\Process::__construct(): Argument #1 ($command) must be of type array, string given,
called in src/Task/Process/CommandRunnerTask.php on line 35

Tested on main (f8201fe), PHP 8.5, Symfony 7.4. CommandRunnerTask.php is unchanged on current main (e70a620).

Cause

In CommandRunnerTask::execute():

  1. $process->setOptions($options) receives the whole resolved options array (commandline, cwd, env, timeout, options). Process::setOptions() only accepts blocking_pipes, create_process_group and create_new_console. The intent was to pass the task's options option: $options['options'].
  2. new Process() only accepts an array command. A string commandline must go through Process::fromShellCommandline().

The reference documentation added in #188 already describes the failure in its Notes section.

Proposed fix

  • pass only $options['options'] to Process::setOptions(), and only when it is not null;
  • use Process::fromShellCommandline() when commandline is a string;
  • validate the types of cwd, env, timeout and options;
  • update docs/reference/tasks/command_runner_task.md: remove the Notes section and document options.

Fixed by #187.

Requirements

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

Breaking changes

None: every configuration of this task currently fails, so no working setup can break.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions