Allow JsonProcessOutputCallback and other Composer runner callbacks to gracefully handle deprecated command options

Created on 30 January 2023, almost 2 years ago
Updated 20 April 2023, over 1 year ago

Problem/Motivation

Follow-up to 📌 ComposerSettingsValidator should run `composer config` to determine if HTTPS is enabled Fixed

Currently `\Drupal\package_manager\JsonProcessOutputCallback::getOutputData` will fail if error buffer has output

But if you pass a deprecated option this could happen

for instance
composer show --installed --format=json

will have

You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.

in the error buffer the but the output buffer should still have the correct json

but we can't test this currently because of 🐛 The 'fake_site' fixture cannot be using with `composer show` because the packages are not installed Fixed

This problem would be more of problem if you using `JsonProcessOutputCallback` for composer operations that made changes because we would throw an exception even though the operation would have succeed. The operation truly did not succeed the call to \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface::run would actually fail so you would never get to the callback.

Currently we are only using `JsonProcessOutputCallback non-destructive commands and not passing deprecated values and this class is internal

Steps to reproduce

Proposed resolution

  1. Create a \Drupal\package_manager\ProcessOutputCallback call to replace the anonymous classed in \Drupal\package_manager\ComposerInspector::getConfig and \Drupal\package_manager\Validator\ComposerExecutableValidator::runCommand
  2. This handle the error buffer as:
    1. If it has output buffer data even if there is also error buffer output return the output buffer
    2. If there is error buffer data and no output buffer data throw an exception with the error buffer data
  3. JsonProcessOutputCallback should just extend ProcessOutputCallback to encode the output

Remaining tasks

ProcessOutputCallback needs test coverage. It may make sense to move some of JsonProcessOutputCallbackTest to a test for ProcessOutputCallback instead

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇺🇸United States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024