Skip to content

fix(cli): stderr warnings are silently discarded on successful commandsΒ #6215

Description

@devantler

πŸ€– Generated by the Daily AI Engineer

Evidence & problem

Every warning a command writes to its stderr during a successful run is silently discarded β€” it never reaches CLI users. This affects real, intentional warnings: workload validate/scan Helm-render degradations ("skipped Helm render …"), --include-crd-schemas "skipped CRD schema …" notices, and CEL rule warnings.

Reproduction: run ksail workload validate <dir> on a kustomization whose HelmRelease chart cannot be resolved offline (e.g. an unreachable oci:// source). Validation degrades gracefully and passes β€” but the "skipped Helm render …" warning that warnDegradations emits never appears on stderr. The in-process tests pass because they run the command with a captured buffer, so the bug is invisible to the test suite.

Root cause

pkg/cli/ui/errorhandler/executor.go redirects the command's stderr into an in-memory buffer for the whole run so it can normalize the final Cobra error message:

cmd.SetErr(&errBuf)
defer cmd.SetErr(originalErrWriter)
err := cmd.Execute()
if err == nil { return nil }   // errBuf (incl. all warnings) discarded on success

On success errBuf is dropped, so every non-error stderr write made during the run is lost. The capture itself is intentional (it turns a failing command's stderr into the normalized CommandError), but it also swallows legitimate warnings.

Expected behaviour

Warnings/notices written to stderr during a successful run reach the real stderr. The error-normalization path (capture β†’ normalize β†’ single clean print) stays unchanged.

Candidate fix (small, low-risk)

On the success branch, flush the captured buffer to the original stderr writer before returning nil (empty buffer β‡’ no-op, so silent commands are unaffected). The error path is untouched. A regression test asserts a warning written by a succeeding command reaches the real stderr.

Acceptance criteria

  • A warning written to cmd.ErrOrStderr() by a command that returns nil reaches the real stderr.
  • Error normalization and exit codes are unchanged (existing executor tests stay green).
  • Regression test covers the success-with-warning case.

Size: S. Impact: unblocks all degradation/CRD/CEL warnings across the CLI (they are correct but currently invisible).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    βœ… Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions