Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sfdx package install always outputs to stderr even when the operation is successful #2004

Closed
dribb-sprout opened this issue Mar 17, 2023 · 8 comments
Labels
bug Issue or pull request that identifies or fixes a bug investigating We're actively investigating this issue more information required Issue requires more information or a response from the customer

Comments

@dribb-sprout
Copy link

dribb-sprout commented Mar 17, 2023

Summary

When using the sfdx package install command to install packages in scratch orgs, the output is always returned to stderr, even when the installation operation succeeds without errors.

This causes issues when using these commands in CI/CD pipelines, scripts, etc, that expect commands to output to stdout for success and stderr for errors/failures.

This does NOT appear to be the case when using other commands (such as sfdx package install report), meaning the output is successfully sent to stdout.

Steps To Reproduce:

  1. Create a new scratch org, example: sfdx force org create --setalias dev-test -f config/project-scratch-def.json
  2. Attempt to install a package to the org and pipe the output of stdout to a file, for example: sfdx package install --package 04t4R000001RcTAQA0 -o dev-test --no-prompt --wait 60 > stdout.txt
  3. Observe that stdout.txt file is empty while running command and after completion
  4. Attempt to install a package to the org and pipe the output of stderr to a file, for example: sfdx package install --package 04t4R000001RcTAQA0 -o dev-test --no-prompt --wait 60 2> stderr.txt
  5. Observe that stderr.txt file contains the output from the command even when it's successful

Expected result

When the operation is successful, I would expect the output to go to stdout and not stderr.

Actual result

The output is returned to stderr.

System Information

  • Which shell/terminal are you using?

    • Tested on both bash and zsh
  • If you are using sfdx

    • Run sfdx version --verbose --json
  • If you are using sf

    • Run sf version --verbose --json
  • Paste the output here: sfdx-cli/7.190.2 darwin-x64 node-v18.14.1

@dribb-sprout dribb-sprout added the investigating We're actively investigating this issue label Mar 17, 2023
@github-actions
Copy link

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

@iowillhoit
Copy link
Contributor

iowillhoit commented Mar 17, 2023

Hey @dribb-sprout, thanks for the issue. That is odd.

  • After running the command (without the file redirect) can you run echo $? to output the exitcode of the last command?
  • Can you provide the output of the sfdx package install command with the --json flag?
  • Are you seeing this with any other packaging commands or just create?
  • Could you provide the full output of sfdx version --verbose --json so we can rule out any plugin issues?
    Thanks!

@dribb-sprout
Copy link
Author

dribb-sprout commented Mar 17, 2023

Hi @iowillhoit - Thanks for looking into this!

  • Running echo $? after the command executes results in an exit code of 0 - I tried both with and without the --wait option, and in both cases it returns 0, but the output is still going to stderr instead of stdout
  • Here is the result when running the command with the --json option (interestingly the JSON output DOES go to stdout instead of stderr):
{
  "status": 0,
  "result": {
    "attributes": {
      "type": "PackageInstallRequest",
      "url": "/services/data/v57.0/tooling/sobjects/PackageInstallRequest/0Hf6t000000H2H6CAK"
    },
    "Id": "0Hf6t000000H2H6CAK",
    "IsDeleted": false,
    "CreatedDate": "2023-03-17T21:51:43.000+0000",
    "CreatedById": "0056t000002kDXXAA2",
    "LastModifiedDate": "2023-03-17T21:51:43.000+0000",
    "LastModifiedById": "0056t000002kDXXAA2",
    "SystemModstamp": "2023-03-17T21:51:43.000+0000",
    "SubscriberPackageVersionKey": "04t4R000001RcTAQA0",
    "NameConflictResolution": "Block",
    "SecurityType": "None",
    "PackageInstallSource": "U",
    "ProfileMappings": null,
    "Password": null,
    "EnableRss": false,
    "UpgradeType": "mixed-mode",
    "ApexCompileType": "all",
    "Status": "SUCCESS",
    "Errors": null
  },
  "warnings": []
}
  • So far I'm only seeing it with sfdx package install - with sfdx package install report, for example, it seems to be outputting to stdout as expected
  • Here is the JSON output when running sfdx version --verbose --json
{
  "cliVersion": "sfdx-cli/7.190.2",
  "architecture": "darwin-x64",
  "nodeVersion": "node-v18.14.1",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 2.1.2 (core)",
    "@oclif/plugin-commands 2.2.10 (core)",
    "@oclif/plugin-help 5.2.5 (core)",
    "@oclif/plugin-not-found 2.3.20 (core)",
    "@oclif/plugin-plugins 2.3.2 (core)",
    "@oclif/plugin-search 0.0.13 (core)",
    "@oclif/plugin-update 3.1.5 (core)",
    "@oclif/plugin-version 1.2.1 (core)",
    "@oclif/plugin-warn-if-update-available 2.0.28 (core)",
    "@oclif/plugin-which 2.2.16 (core)",
    "@salesforce/lwc-dev-server 2.11.0 (user)",
    "alias 2.2.2 (core)",
    "apex 2.2.0 (core)",
    "auth 2.7.1 (core)",
    "community 2.2.3 (core)",
    "config 1.5.1 (core)",
    "custom-metadata 2.1.3 (core)",
    "data 2.3.1 (core)",
    "info 2.4.4 (core)",
    "limits 2.3.5 (core)",
    "org 2.4.2 (core)",
    "packaging 1.15.0 (core)",
    "schema 2.3.1 (core)",
    "signups 1.4.3 (core)",
    "source 2.5.4 (core)",
    "telemetry 2.1.1 (core)",
    "templates 55.4.1 (core)",
    "trust 2.4.2 (core)",
    "user 2.3.2 (core)",
    "@salesforce/sfdx-plugin-lwc-test 1.0.1 (core)"
  ],
  "osVersion": "Darwin 22.3.0",
  "shell": "zsh",
  "rootPath": "/Users/dylanribb/.local/share/sfdx/client/7.190.2-cd6cf69"
}

@dribb-sprout
Copy link
Author

dribb-sprout commented Mar 17, 2023

@iowillhoit - I did a little digging and I think this line in the plugin-packaging plugin might be the culprit: https://github.com/salesforcecli/plugin-packaging/blob/dc8935801c057778fa20e09b1d20c59741683030/src/commands/package/install.ts#L200

It looks like the SpinnerAction class from @oclif/core inherits from ActionBase (also from @oclif/core), and the parent/base class defaults to writing to stderr unless it's explicitly provided an option flag telling it to write to stdout.

I imagine that other commands that use that spinner for output/as a dependency likely have the same behavior. I noticed that the report command doesn't appear to be using that spinner anywhere, which would probably explain why I wasn't seeing the same behavior there.

@mshanemc mshanemc added the bug Issue or pull request that identifies or fixes a bug label Mar 21, 2023
@git2gus
Copy link

git2gus bot commented Mar 21, 2023

This issue has been linked to a new work item: W-12726817

@iowillhoit
Copy link
Contributor

Awesome, thank you for the additional detail @dribb-sprout ! We'll get it looked at.

@peternhale
Copy link
Contributor

@dribb-sprout I was looking at this issue and tried to reproduced so I might find a fix. However I cannot reproduce the behavior.

Using sfdx-cli/7.191.1 I ran

sfdx package install --package 04t4R000001RcTAQA0 --no-prompt --wait 60 > stdout.txt 
Waiting 60 minutes for package install to complete.... done
% cat stdout.txt 
Successfully installed package [04t4R000001RcTAQA0]

The progress reported by the install is being written to stderr (as described above), but I am getting the final result redirected to a file.

@cristiand391 cristiand391 added the more information required Issue requires more information or a response from the customer label Mar 30, 2023
@mshanemc mshanemc closed this as completed May 8, 2023
@mshanemc mshanemc reopened this May 8, 2023
@shetzel
Copy link
Contributor

shetzel commented Nov 28, 2023

This was fixed a few releases ago. Please reopen if you are still seeing the problem after updating your CLI to the latest.

@shetzel shetzel closed this as completed Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue or pull request that identifies or fixes a bug investigating We're actively investigating this issue more information required Issue requires more information or a response from the customer
Projects
None yet
Development

No branches or pull requests

6 participants