Skip to content

OCM-23148 | fix: format errors and warnings as JSON on stderr when --output flag is set#3226

Open
mmahut wants to merge 1 commit intoopenshift:masterfrom
mmahut:master
Open

OCM-23148 | fix: format errors and warnings as JSON on stderr when --output flag is set#3226
mmahut wants to merge 1 commit intoopenshift:masterfrom
mmahut:master

Conversation

@mmahut
Copy link
Copy Markdown

@mmahut mmahut commented Mar 23, 2026

PR Summary

Respect --output for runtime errors and warnings so commands do not emit plain reporter output when machine-readable output is requested.

Detailed Description of the Issue

When --output json or --output yaml is used, some runtime error and warning paths still go through the standard reporter and print human-readable output such as E: or W: lines. That breaks automation expecting structured output.

This was reported in rosa whoami --output json, where authentication failures produced plain text instead of JSON. The issue is not limited to a single command path, so this change updates the runtime reporter behavior rather than fixing only one command.

Related Issues and PRs

Type of Change

  • fix - resolves an incorrect behavior or bug.
  • feat - adds a new user-facing capability.
  • docs - updates documentation only.
  • style - formatting or naming changes with no logic impact.
  • refactor - code restructuring with no behavior change.
  • test - adds or updates tests only.
  • chore - maintenance work (tooling, housekeeping, non-product code).
  • build - changes build system, packaging, or dependencies for build output.
  • ci - changes CI pipelines, jobs, or automation workflows.
  • perf - improves performance without changing intended behavior.

Previous Behavior

Commands invoked with --output json or --output yaml could still print plain reporter-formatted errors and warnings.

Example:

$ ./rosa whoami --output json
E: Failed to create OCM connection: Not logged in, run the 'rosa login' command

Behavior After This Change

Runtime-reported errors and warnings now honor --output and are emitted as structured JSON on stderr, while the default non-structured behavior remains unchanged.

Example:

$ ./rosa whoami --output json
{"error":"Failed to create OCM connection: Not logged in, run the 'rosa login' command"}

$ ./rosa whoami
E: Failed to create OCM connection: Not logged in, run the 'rosa login' command

How to Test (Step-by-Step)

Preconditions

  • Build the CLI from this branch
  • Use an environment without a valid rosa login token

Test Steps

  1. Run ./rosa whoami --output json
  2. Run ./rosa whoami
  3. Trigger another runtime-level warning or error path with --output json or --output yaml

Expected Results

  • ./rosa whoami --output json prints a valid JSON error object
  • ./rosa whoami keeps the existing human-readable reporter output
  • Other runtime-reported warnings and errors also respect structured output mode

Proof of the Fix

  • Screenshots: N/A
  • Videos: N/A
  • Logs/CLI output:
$ ./rosa whoami --output json
{"error":"Failed to create OCM connection: Not logged in, run the 'rosa login' command"}

$ ./rosa whoami
E: Failed to create OCM connection: Not logged in, run the 'rosa login' command
  • Other artifacts: unit tests added/updated for structured reporter and output helpers

Breaking Changes

  • No breaking changes
  • Yes, this PR introduces a breaking change (describe impact and migration plan below)

Breaking Change Details / Migration Plan

N/A

Developer Verification Checklist

  • Commit subject/title follows [JIRA-TICKET] | [TYPE]: <MESSAGE>.
  • PR description clearly explains both what changed and why.
  • Relevant Jira/GitHub issues and related PRs are linked.
  • Tests were added/updated where appropriate.
  • I manually tested the change.
  • make test passes.
  • make lint passes.
  • make rosa passes.
  • Documentation was added/updated where appropriate.
  • Any risk, limitation, or follow-up work is documented.

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 23, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Mar 23, 2026

Hi @mmahut. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@olucasfreitas
Copy link
Copy Markdown
Contributor

/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 26, 2026
@olucasfreitas olucasfreitas changed the title fix: format errors and warnings as JSON on stderr when --output flag is set OCM-23148 | fix: format errors and warnings as JSON on stderr when --output flag is set Mar 26, 2026
@olucasfreitas
Copy link
Copy Markdown
Contributor

@mmahut thanks for this PR, I left some comments and would like to requests that you:

  • fix the commit message to adhere to our commit standarts
  • squash all commits into that message
  • fill out the PR template on the repo so we can have some more context if needed, and also because it helps with our testing

olucasfreitas

This comment was marked as off-topic.

@mmahut mmahut force-pushed the master branch 2 times, most recently from 40c87f0 to 6389497 Compare April 1, 2026 16:26
@mmahut
Copy link
Copy Markdown
Author

mmahut commented Apr 1, 2026

Hello @olucasfreitas,

Thank you for your comments! I have amended the commit message as well as did update the PR description to use the entire template.

@olucasfreitas
Copy link
Copy Markdown
Contributor

/retest

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 2, 2026

@mmahut: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/lint 71a41c7 link true /test lint
ci/prow/test 71a41c7 link true /test test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@olucasfreitas
Copy link
Copy Markdown
Contributor

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 6, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 6, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mmahut, olucasfreitas

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 6, 2026
@olucasfreitas
Copy link
Copy Markdown
Contributor

@mmahut thanks for the PR, approved and just waiting for merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"rosa whoami --output json" errors are not json

2 participants