Skip to content

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

@Elvand-Lie

Description

@Elvand-Lie

Description

The write() function in cmd/format.go (line 46) uses panic(err) when it encounters either an unrecognized output format name or a serialization error. This crashes the CLI process instead of showing a graceful error message via cobra's error handling.

This is the only panic in the cmd/ package outside of test code and the fundamentally-unrecoverable effectivePath() function.

Compounding issue

cmd/list.go (line 71) advertises xml as a valid output format in its --output flag help text:

Output format (human|plain|json|xml|yaml)

But there is no XML case in the write() switch, no XML() method on the Formatter interface, and no XML constant. Running func list --output xml triggers the panic and crashes.

Expected Behavior

  • Invalid --output values should produce a graceful error message
  • The help text should only list actually-implemented formats

Steps to Reproduce

�ash func list --output xml # panics func list --output typo # also panics func describe --output bad # also panics

Proposed Fix

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

/kind bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions