{"record":{"id":"e77c9edf5b2295b1","repo":"kubernetes/kops","slug":"unknown-output-format-q-e77c9e","errorCode":null,"errorMessage":"unknown output format: %q","messagePattern":"unknown output format: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_keypairs.go","lineNumber":256,"sourceCode":"\tcase OutputYaml:\n\t\ty, err := yaml.Marshal(items)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to marshal YAML: %v\", err)\n\t\t}\n\t\tif _, err := out.Write(y); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to output: %v\", err)\n\t\t}\n\tcase OutputJSON:\n\t\tj, err := json.Marshal(items)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to marshal JSON: %v\", err)\n\t\t}\n\t\tif _, err := out.Write(j); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to output: %v\", err)\n\t\t}\n\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown output format: %q\", options.Output)\n\t}\n\n\treturn nil\n}\n\nfunc completeGetKeypairs(ctx context.Context, f commandutils.Factory, options *GetKeypairsOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\tcommandutils.ConfigureKlogForCompletion()\n\n\tcluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)\n\tif cluster == nil {\n\t\treturn completions, directive\n\t}\n\n\talreadySelected := sets.NewString(args...).Insert(\"all\")\n\t_, _, completions, directive = completeKeyset(ctx, cluster, clientSet, nil, func(name string, keyset *fi.Keyset) bool {\n\t\treturn !alreadySelected.Has(name)\n\t})\n","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_keypairs.go#L238-L274","documentation":"RunGetKeypairs validates options.Output against table, yaml, and json; any other value falls into the switch's default branch and returns \"unknown output format: %q\". Like the get_instances equivalent, it is strict input validation, and note the wording differs from get_instances (\"unknown\" vs \"unsupported\").","triggerScenarios":"`kops get keypairs -o xml`, `-o`, `-o wide`, or an uppercase/mixed-case value; the empty default if a wrapper script passes an uninitialized OUTPUT variable.","commonSituations":"Script variables left empty (`-o \"$FMT\"` with FMT unset); copying flags from other tools (kubectl's `-o wide` does not exist here); case sensitivity assumptions (YAML vs yaml).","solutions":["Use one of: `kops get keypairs -o table|yaml|json`.","Ensure the format variable in scripts is non-empty and lowercase.","Check `kops get keypairs --help` for accepted -o values.","If you need another format, post-process the JSON/yaml output with jq/yq instead."],"exampleFix":"// before\nFMT=\"\"; kops get keypairs -o \"$FMT\"   # unknown output format: \"\"\n// after\nFMT=\"json\"; kops get keypairs -o \"$FMT\"","handlingStrategy":"validation","validationCode":"FMT=\"${OUTPUT:-json}\"\ncase \"$FMT\" in\n  table|yaml|json) ;;\n  *) echo \"invalid output '$FMT'; use table|yaml|json\" >&2; exit 2 ;;\nesac\nkops get keypairs -o \"$FMT\"","typeGuard":null,"tryCatchPattern":"if err := runKops(\"get\", \"keypairs\", \"-o\", format); err != nil {\n\tif strings.Contains(err.Error(), \"unknown output format\") {\n\t\treturn fmt.Errorf(\"%q rejected: must be table, yaml, or json\", format)\n\t}\n\treturn err\n}","preventionTips":["Default the format variable to a valid value (${OUTPUT:-json}) in scripts.","Only use lowercase table/yaml/json — kubectl-only formats like 'wide' are unsupported.","Derive alternate formats from JSON via jq/yq instead of expecting CLI support.","Verify flags with `kops get keypairs --help` when porting scripts between tools."],"tags":["cli","input-validation","flags"],"backgroundTag":"invalid-flag-value","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}