kubernetes/kops · error
unknown output format: %q
Error message
unknown output format: %q
What it means
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").
Source
Thrown at cmd/kops/get_keypairs.go:256
case OutputYaml:
y, err := yaml.Marshal(items)
if err != nil {
return fmt.Errorf("unable to marshal YAML: %v", err)
}
if _, err := out.Write(y); err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
case OutputJSON:
j, err := json.Marshal(items)
if err != nil {
return fmt.Errorf("unable to marshal JSON: %v", err)
}
if _, err := out.Write(j); err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
default:
return fmt.Errorf("unknown output format: %q", options.Output)
}
return nil
}
func completeGetKeypairs(ctx context.Context, f commandutils.Factory, options *GetKeypairsOptions, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
commandutils.ConfigureKlogForCompletion()
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, f, nil)
if cluster == nil {
return completions, directive
}
alreadySelected := sets.NewString(args...).Insert("all")
_, _, completions, directive = completeKeyset(ctx, cluster, clientSet, nil, func(name string, keyset *fi.Keyset) bool {
return !alreadySelected.Has(name)
})
View on GitHub (pinned to 4c8573c808)
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.
Example fix
// before FMT=""; kops get keypairs -o "$FMT" # unknown output format: "" // after FMT="json"; kops get keypairs -o "$FMT"
Defensive patterns
Strategy: validation
Validate before calling
FMT="${OUTPUT:-json}"
case "$FMT" in
table|yaml|json) ;;
*) echo "invalid output '$FMT'; use table|yaml|json" >&2; exit 2 ;;
esac
kops get keypairs -o "$FMT" Try / catch
if err := runKops("get", "keypairs", "-o", format); err != nil {
if strings.Contains(err.Error(), "unknown output format") {
return fmt.Errorf("%q rejected: must be table, yaml, or json", format)
}
return err
} Prevention
- 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.
When it happens
Trigger: `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.
Common situations: 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).
Understand the failure class
Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.
Related errors
- unsupported output format: %q
- unsupported output type %q
- --name is required
- cannot specify --cert with "all"
- cannot use both --admin and --user
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/e77c9edf5b2295b1.
Report an issue: GitHub.