Skip to content

fix(cmd): replace panic with error return in write() and remove phantom xml format#3845

Open
Elvand-Lie wants to merge 2 commits into
knative:mainfrom
Elvand-Lie:fix/format-write-panic-and-phantom-xml
Open

fix(cmd): replace panic with error return in write() and remove phantom xml format#3845
Elvand-Lie wants to merge 2 commits into
knative:mainfrom
Elvand-Lie:fix/format-write-panic-and-phantom-xml

Conversation

@Elvand-Lie
Copy link
Copy Markdown
Contributor

Fixes #3844

Changes

The write() function in cmd/format.go used panic(err) when encountering an unrecognized output format or serialization error. This crashes the CLI process instead of showing a graceful error message.

Additionally, list.go advertised xml as a valid output format in its --output flag help text, but XML was never implemented. Passing --output xml would trigger the panic.

What this PR does:

  1. cmd/format.go: Change write() to return error instead of panicking
  2. cmd/list.go, cmd/describe.go, cmd/version.go: Update all three callers to propagate the returned error
  3. cmd/list.go: Remove xml from the --output flag help text

Testing

The change is minimal and type-safe - the function signature change from func write(...) to func write(...) error forces all callers to handle the error. Previously-panicking code paths now return errors through cobra's standard error handling.

/kind bug

@knative-prow knative-prow Bot added kind/bug Bugs size/M 🤖 PR changes 30-99 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 25, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 25, 2026

Hi @Elvand-Lie. Thanks for your PR.

I'm waiting for a knative 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.

@knative-prow knative-prow Bot requested a review from dsimansk May 25, 2026 15:45
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 25, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Elvand-Lie
Once this PR has been reviewed and has the lgtm label, please assign dprotaso for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@knative-prow knative-prow Bot requested a review from jrangelramos May 25, 2026 15:45
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 63.63636% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.46%. Comparing base (e7d7dcf) to head (c1d3836).

Files with missing lines Patch % Lines
cmd/format.go 57.14% 3 Missing ⚠️
cmd/list.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3845      +/-   ##
==========================================
+ Coverage   53.44%   53.46%   +0.02%     
==========================================
  Files         200      200              
  Lines       23450    23443       -7     
==========================================
+ Hits        12533    12534       +1     
+ Misses       9662     9657       -5     
+ Partials     1255     1252       -3     
Flag Coverage Δ
e2e 33.71% <54.54%> (-0.01%) ⬇️
e2e go 29.66% <36.36%> (-0.01%) ⬇️
e2e node 25.95% <36.36%> (-0.01%) ⬇️
e2e python 29.99% <36.36%> (-0.01%) ⬇️
e2e quarkus 26.06% <36.36%> (-0.01%) ⬇️
e2e rust 25.53% <36.36%> (-0.01%) ⬇️
e2e springboot 24.19% <36.36%> (-0.02%) ⬇️
e2e typescript 26.05% <36.36%> (-0.01%) ⬇️
e2e-config-ci 26.78% <36.36%> (+<0.01%) ⬆️
integration 15.77% <0.00%> (+0.01%) ⬆️
unit macos-14 42.22% <63.63%> (-0.01%) ⬇️
unit macos-latest 42.22% <63.63%> (-0.01%) ⬇️
unit ubuntu-24.04-arm 42.52% <63.63%> (-0.01%) ⬇️
unit ubuntu-latest 43.09% <63.63%> (-0.01%) ⬇️
unit windows-latest 42.29% <63.63%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…om xml format

The write() function in format.go used panic(err) when encountering an
unrecognized output format or serialization error. This crashes the CLI
process instead of showing a graceful error message.

Additionally, list.go advertised 'xml' as a valid output format in its
--output flag help text, but XML was never implemented. Passing
--output xml would trigger the panic.

Changes:
- Change write() to return error instead of panicking
- Update all three callers (list, describe, version) to propagate the error
- Remove 'xml' from list command's --output flag help text

Signed-off-by: Elvand-Lie <nicholasdwiputra@gmail.com>
@Elvand-Lie Elvand-Lie force-pushed the fix/format-write-panic-and-phantom-xml branch from df84478 to c1d3836 Compare May 25, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Bugs needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd: write() in format.go panics instead of returning error; list advertises unsupported xml format

1 participant