{"record":{"id":"a999c8aaf49bd44c","repo":"istio/istio","slug":"output-must-be-yaml-or-json","errorCode":null,"errorMessage":"--output must be 'yaml' or 'json'","messagePattern":"--output must be 'yaml' or 'json'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/version/cobra.go","lineNumber":72,"sourceCode":"}\n\n// CobraCommandWithOptions returns a command used to print version information.\n// It accepts an CobraOptions argument that might modify its behavior\nfunc CobraCommandWithOptions(options CobraOptions) *cobra.Command {\n\tvar (\n\t\tshort         bool\n\t\toutput        string\n\t\tremote        bool\n\t\tversion       Version\n\t\tremoteVersion *MeshInfo\n\t)\n\n\tcmd := &cobra.Command{\n\t\tUse:   \"version\",\n\t\tShort: \"Prints out build version information\",\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tif output != \"\" && output != \"yaml\" && output != \"json\" {\n\t\t\t\treturn errors.New(`--output must be 'yaml' or 'json'`)\n\t\t\t}\n\n\t\t\tversion.ClientVersion = &Info\n\n\t\t\tif options.GetRemoteVersion != nil && remote {\n\t\t\t\tremoteVersion, _ = options.GetRemoteVersion()\n\t\t\t\tversion.MeshVersion = remoteVersion\n\t\t\t}\n\t\t\tif options.GetProxyVersions != nil && remote {\n\t\t\t\tversion.DataPlaneVersion, _ = options.GetProxyVersions()\n\t\t\t}\n\n\t\t\tswitch output {\n\t\t\tcase \"\":\n\t\t\t\tif short {\n\t\t\t\t\t_, _ = fmt.Fprintf(cmd.OutOrStdout(), \"client version: %s\\n\", version.ClientVersion.Version)\n\t\t\t\t\tif remoteVersion != nil {\n\t\t\t\t\t\tremoteVersion = coalesceVersions(remoteVersion)","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/istio/istio/blob/8dc789c5cf17517c64e3c36cb3288230f149dfae/pkg/version/cobra.go#L54-L90","documentation":"The `istioctl version` command validates its `--output` flag and only accepts 'yaml' or 'json' (plus default human-readable when empty). Any other value is rejected with this error before any version info is printed. Simple CLI argument validation.","triggerScenarios":"Running `istioctl version -o wide`, `-o table`, `-o NAME`, or any typo like `--output=jason`; also scripts that pass an unset shell variable that expands to garbage.","commonSituations":"Muscle memory from kubectl (`-o wide`/`-o jsonpath=...`); CI scripts assuming kubectl-compatible output formats; shell variable that is empty-but-quoted oddly or misspelled.","solutions":["Use `--output yaml` or `--output json` (or the shorthand `-o yaml`/`-o json`).","Omit the flag entirely for the default human-readable summary.","In scripts, default the variable: `OUTPUT=${OUTPUT:-json}`."],"exampleFix":"# before\nistioctl version -o wide\n\n# after\nistioctl version\n# or\nistioctl version -o json","handlingStrategy":"validation","validationCode":"outFlag := os.Getenv(\"ISTIOCTL_OUTPUT\")\nif outFlag != \"\" && outFlag != \"yaml\" && outFlag != \"json\" {\n    outFlag = \"json\"\n}","typeGuard":null,"tryCatchPattern":"Not applicable — validate the flag before invoking istioctl; on non-zero exit, print the error and re-run with a supported value.","preventionTips":["Pin supported formats in wrapper scripts.","Do not assume kubectl -o semantics transfer to istioctl."],"tags":["istio","istioctl","cli","usage-error"],"backgroundTag":null,"analyzedSha":"8dc789c5cf17517c64e3c36cb3288230f149dfae","analyzedAt":"2026-08-15T15:16:55.434Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}