acquia / cli

Command-line interface for Acquia Cloud Platform products
https://docs.acquia.com/acquia-cli/
GNU General Public License v2.0
42 stars 47 forks source link

CLI-1276: JSON format break: Notice: Composer script `post-acli-api-applications-list` does not exist in `composer.json`, skipping. This is not an error. #1686

Closed fiasco closed 6 months ago

fiasco commented 6 months ago

Describe the bug When post-acli-api-applications-list does not exist in composer.json a notice is echoed to stdout which breaks json formatting on api:applications:list calls. JQ does not seem affected by this, but attempting to decode this output in PHP fails.

To Reproduce

  1. Use Symfony Process component to run acli api:applications:list
  2. Pass the getOutput response to json_decode in PHP.
  3. Get null instead of an application data object (or array).
fiasco commented 6 months ago

Also the case with api:applications:environment-list

danepowell commented 6 months ago

I'm going to need more information to reproduce this. I can run acli api:applications:list from any directory just fine (including ones with no composer.json, or composer.json without scripts), there's no PHP notice.

What does it mean to Use Symfony Process component to run the process? That doesn't sound like a supported use case.

fiasco commented 6 months ago

Is it possible that acli read into a local composer.json file it found? I can't reproduce this error now and I'm not exactly sure whats changed.

danepowell commented 6 months ago

Oh, were you running the command with verbose output? That will output additional non-JSON text. That seems like expected behavior to me. I can't imagine how you'd output "verbose" JSON. I guess we could at least print another warning saying the output won't be JSON with verbose output, so people don't think this is a bug.

For posterity: here's the code that handles Composer hooks: https://github.com/acquia/cli/blob/main/src/EventListener/ComposerScriptsListener.php

In a nutshell:

  1. If you pass --no-scripts, nothing happens (I actually found a bug in this: https://github.com/acquia/cli/pull/1688 )
  2. It looks for composer.json in your project dir, which is generally the Symfony Kernel ProjectDir but may be ACLI_REPO_ROOT if you've set that. I think we may be abusing this somewhat, since the Symfony docs talk about this being the root of a Symfony application but of course you might run ACLI in the context of a Composer-based non-Symfony app. I don't know what happens in that case.
  3. If composer.json exists, you'll see verbose output indicating whether the script was found and run or not.
danepowell commented 6 months ago

Let me know if you need more help.