istio/istio · error
invalid format, expected one of %v but got %q
Error message
invalid format, expected one of %v but got %q
What it means
Print renders analysis/diagnostic messages in the requested output format and rejects anything outside the supported set (log, json, yaml — from MsgOutputFormatKeys). This is the istioctl `--output` / -o flag validator for analyze-style message output.
Source
Thrown at istioctl/pkg/util/formatting/formatter.go:60
)
func init() {
for _, key := range MsgOutputFormatKeys {
MsgOutputFormats[key] = true
}
}
// Print output messages in the specified format with color options
func Print(ms diag.Messages, format string, colorize bool) (string, error) {
switch format {
case LogFormat:
return printLog(ms, colorize), nil
case JSONFormat:
return printJSON(ms)
case YAMLFormat:
return printYAML(ms)
default:
return "", fmt.Errorf("invalid format, expected one of %v but got %q", MsgOutputFormatKeys, format)
}
}
func printLog(ms diag.Messages, colorize bool) string {
logOutput := make([]string, 0, len(ms))
for _, m := range ms {
logOutput = append(logOutput, render(m, colorize))
}
return strings.Join(logOutput, "\n")
}
func printJSON(ms diag.Messages) (string, error) {
jsonOutput, err := json.MarshalIndent(ms, "", "\t")
return string(jsonOutput), err
}
func printYAML(ms diag.Messages) (string, error) {
yamlOutput, err := yaml.Marshal(ms)View on GitHub (pinned to 8dc789c5cf)
Solutions
- Use one of the printed valid keys: log, json, or yaml.
- If you need machine-readable output for analysis results, use `-o json` or `-o yaml` and post-process with jq/yq.
- Check MsgOutputFormatKeys in the istioctl version in use — the valid set is printed in the error.
Example fix
# before istioctl analyze -o wide # after istioctl analyze -o json
Defensive patterns
Strategy: validation
Validate before calling
valid := map[string]bool{"log": true, "json": true, "yaml": true}
if !valid[format] {
return fmt.Errorf("unsupported format %q; use log|json|yaml", format)
} Type guard
func IsValidMsgOutputFormat(f string) bool {
for _, k := range formatting.MsgOutputFormatKeys {
if f == k { return true }
}
return false
} Prevention
- Restrict -o flags in wrapper scripts to the printed valid set.
- Do not port kubectl format assumptions to istioctl.
- Parse the error's valid-key list to auto-correct typos in interactive tools.
When it happens
Trigger: Passing an unsupported -o value to commands that route through this Print (e.g. `istioctl analyze -o table`, `-o wide`, `-o xml`) — only log/json/yaml are accepted here, unlike kubectl's richer format set.
Common situations: Muscle memory from kubectl (`-o wide`, `-o name`, `-o jsonpath=...`) applied to istioctl analyze; scripts assuming table output is a valid format string.
Related errors
- filename not specified (see --filename or -f)
- invalid level option
- output format %q not supported
- pattern %s did not match
- metrics requires workload name
AI-assisted analysis of istio/istio@8dc789c5cf (2026-08-15).
Data as JSON: /api/errors/d72506b421a1b96d.
Report an issue: GitHub.