cli icon indicating copy to clipboard operation
cli copied to clipboard

[Bug]: Logging should be done to STDERR by default. STDOUT should be reserved for scriptable output.

Open charlespwd opened this issue 1 year ago • 10 comments

Please confirm that you have:

  • [X] Searched existing issues to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
  • [X] Reproduced the issue in the latest CLI version.

In which of these areas are you experiencing a problem?

Other

Expected behavior

I noticed that logging is done by default to STDOUT (even debug logging, for theme check anyway). Shouldn’t that be sent to STDERR by default?

Logging to STDOUT when it isn’t meant to be captured by a script makes the CLI non-composable/non-scriptable.

For instance, shopify theme check --verbose --output json will have non-JSON output in STDOUT and makes | jq break.

IMO STDOUT should be intentional, not the default.

Actual behavior

IMO all of these should use STDERR by default. STDOUT is the wrong default.

  • outputDebug should log to STDERR by default (console.error)
  • outputInfo
  • outputWarn

Verbose output

$ shopify theme check --output json --verbose | jq .
jq: parse error: Invalid numeric literal at line 1, column 14

Reproduction steps

  1. shopify theme check --output json --verbose | jq . -- get malformed JSON because debug logging isn't JSON.

Operating System

All

Shopify CLI version (check your project's package.json if you're not sure)

3.60

charlespwd avatar May 07 '24 14:05 charlespwd

+1

knjshimi avatar May 07 '24 20:05 knjshimi

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Jun 22 '24 03:06 github-actions[bot]

If we did this, we wouldn't have had https://github.com/Shopify/lighthouse-ci-action/issues/87

charlespwd avatar Nov 25 '24 13:11 charlespwd

I've created a draft PR with a potential solution for this: https://github.com/Shopify/cli/pull/4922, in case someone wants to continue

gonzaloriestra avatar Nov 27 '24 13:11 gonzaloriestra

I would even suggest having a new output helper named output that would be the only one that logs to STDOUT.

That way you can pick from the list:

  • outputInfo - STDERR loglevel info
  • outputDebug - STDERR loglevel debug
  • outputWarn - STDERR loglevel warn
  • outputError - STDERR loglevel error
  • output - STDOUT. Use only for JSON or whatever could be piped into another bash script.

charlespwd avatar Nov 27 '24 14:11 charlespwd

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Jan 09 '25 03:01 github-actions[bot]

Still relevant

knjshimi avatar Jan 09 '25 04:01 knjshimi

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Mar 05 '25 03:03 github-actions[bot]

still relevant I believe

knjshimi avatar Mar 05 '25 08:03 knjshimi