Skip to content

fix: cli stdout warnings corrupt redirected output#710

Merged
Justiceleeg merged 9 commits intomainfrom
justice/sc-136974/cli-stdout-warnings-corrupt-redirected-output
May 1, 2026
Merged

fix: cli stdout warnings corrupt redirected output#710
Justiceleeg merged 9 commits intomainfrom
justice/sc-136974/cli-stdout-warnings-corrupt-redirected-output

Conversation

@Justiceleeg
Copy link
Copy Markdown
Member

This reverts commit 890004e.
Cobra's auto-emitted output (deprecation warnings, usage-on-error)
was going to stdout, corrupting redirected structured output such
as `cluster kubeconfig --stdout > kubeconfig.yaml`. Align with
cobra's default by setting Out to stderr.

Refs sc-136974
Move the kubeconfig success, backup-removal failure, and
context-updated messages from stdout to stderr so they no longer
corrupt the YAML payload when output is redirected. Also switch
the --stdout data path from Println to Print to avoid an extra
trailing newline.

Refs sc-136974
The auto-discovery branch printed informational text to r.w
(stdout) regardless of output format, breaking JSON parsers when
running `release lint -o json` outside a configured project.
Gate the discovery messages on table format, and have the
empty-result early return emit a valid JSON payload so consumers
always receive parseable output.

Refs sc-136974
Logger TTY checks were hardcoded to os.Stdout.Fd(), so spinners
fired even when the logger had been pointed at a non-TTY writer.
Replace each call site with an isTTY helper that type-asserts the
configured writer. Switch the two `release download` callers from
os.Stdout to os.Stderr — the command's data path writes files to
disk, so progress messages belong on stderr.

Refs sc-136974
`app rm` shares its logger writer with structured output, so the
fetch/delete spinners leaked into the JSON payload. Gate the
spinner calls on `outputFormat == \"table\"` to keep the JSON
output clean.

Refs sc-136974
Comment thread pkg/logger/logger.go
The previous patch broke spinners for any logger built from a
tabwriter wrapping stdout: the type assertion to *os.File failed,
so isTTY() always returned false. Capture the stdout TTY state
once in Execute() and let callers thread it through with
SetIsTerminal so wrapped writers still spin when stdout is a
real terminal.

Refs sc-136974
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6c2f3f0. Configure here.

Comment thread cli/cmd/root.go
Setting cobra Out to stderr also redirected --help, breaking
`replicated --help | grep ...` and `--help > help.txt`. Restore
the CLI convention by overriding the root HelpFunc to write to
stdout while leaving deprecation warnings and usage-on-error on
stderr.

Refs sc-136974
@Justiceleeg Justiceleeg merged commit f33d278 into main May 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants