From b6cce458f5fcdc2a32f5b25b2252adeccfc16c68 Mon Sep 17 00:00:00 2001 From: Tempris Admin Date: Mon, 25 May 2026 22:28:44 +0700 Subject: [PATCH 1/2] fix(cmd): replace panic with error return in write() and remove phantom 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 --- cmd/describe.go | 3 +-- cmd/format.go | 22 +++++++++------------- cmd/list.go | 6 ++---- cmd/version.go | 3 +-- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/cmd/describe.go b/cmd/describe.go index 5a6f4a8d49..f8beb99af2 100644 --- a/cmd/describe.go +++ b/cmd/describe.go @@ -89,8 +89,7 @@ func runDescribe(cmd *cobra.Command, args []string, newClient ClientFactory) (er } } - write(os.Stdout, info(details), cfg.Output) - return + return write(os.Stdout, info(details), cfg.Output) } // CLI Configuration (parameters) diff --git a/cmd/format.go b/cmd/format.go index f403c6e32d..bcad1bc925 100644 --- a/cmd/format.go +++ b/cmd/format.go @@ -24,25 +24,21 @@ type Formatter interface { URL(io.Writer) error } -// write to the output the output of the formatter's appropriate serilization function. -// the command to exit with value 2. -func write(out io.Writer, s Formatter, formatName string) { - var err error +// write the output using the formatter's appropriate serialization function, +// returning any errors to the caller for graceful handling. +func write(out io.Writer, s Formatter, formatName string) error { switch Format(formatName) { case Human: - err = s.Human(out) + return s.Human(out) case Plain: - err = s.Plain(out) + return s.Plain(out) case JSON: - err = s.JSON(out) + return s.JSON(out) case YAML: - err = s.YAML(out) + return s.YAML(out) case URL: - err = s.URL(out) + return s.URL(out) default: - err = fmt.Errorf("format not recognized: %v", formatName) - } - if err != nil { - panic(err) + return fmt.Errorf("format not recognized: %v", formatName) } } diff --git a/cmd/list.go b/cmd/list.go index 451d76e9d1..9fa5a11b38 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -68,7 +68,7 @@ Lists deployed functions. // Flags cmd.Flags().BoolP("all-namespaces", "A", false, "List functions in all namespaces. If set, the --namespace flag is ignored.") cmd.Flags().StringP("namespace", "n", defaultNamespace(fn.Function{}, false), "The namespace for which to list functions. ($FUNC_NAMESPACE)") - cmd.Flags().StringP("output", "o", "human", "Output format (human|plain|json|xml|yaml) ($FUNC_OUTPUT)") + cmd.Flags().StringP("output", "o", "human", "Output format (human|plain|json|yaml) ($FUNC_OUTPUT)") addVerboseFlag(cmd, cfg.Verbose) if err := cmd.RegisterFlagCompletionFunc("output", CompleteOutputFormatList); err != nil { @@ -119,9 +119,7 @@ To see functions here: return } - write(os.Stdout, listItems(items), cfg.Output) - - return + return write(os.Stdout, listItems(items), cfg.Output) } // CLI Configuration (parameters) diff --git a/cmd/version.go b/cmd/version.go index ca14a3824b..da82b99b58 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -95,8 +95,7 @@ func runVersion(cmd *cobra.Command, v Version) error { } v.MiddlewareVersions = latestMW - write(cmd.OutOrStdout(), v, output) - return nil + return write(cmd.OutOrStdout(), v, output) } // Version information populated on build. From c1d38366063b06a9e13d848b6b203637654e6539 Mon Sep 17 00:00:00 2001 From: Tempris Admin Date: Mon, 25 May 2026 22:55:07 +0700 Subject: [PATCH 2/2] docs: update func list reference docs for removed xml format --- docs/reference/func_list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/func_list.md b/docs/reference/func_list.md index f743e66334..522620a030 100644 --- a/docs/reference/func_list.md +++ b/docs/reference/func_list.md @@ -34,7 +34,7 @@ func list --all-namespaces --output json -A, --all-namespaces List functions in all namespaces. If set, the --namespace flag is ignored. -h, --help help for list -n, --namespace string The namespace for which to list functions. ($FUNC_NAMESPACE) (default "default") - -o, --output string Output format (human|plain|json|xml|yaml) ($FUNC_OUTPUT) (default "human") + -o, --output string Output format (human|plain|json|yaml) ($FUNC_OUTPUT) (default "human") -v, --verbose Print verbose logs ($FUNC_VERBOSE) ```