hashicorp/nomad · error
no formatting option given
Error message
no formatting option given
What it means
Format (command/data_format.go) builds a data formatter for Nomad CLI output but requires exactly one formatting option: -json, a -template, or a default format. If none of the json/template flags was supplied and no default was assigned, it refuses to guess and returns "no formatting option given".
Source
Thrown at command/data_format.go:87
}
err = t.Execute(&out, data)
if err != nil {
return "", err
}
return out.String(), nil
}
func Format(json bool, template string, data any) (string, error) {
var format string
if json && len(template) > 0 {
return "", fmt.Errorf("Both json and template formatting are not allowed")
} else if json {
format = "json"
} else if len(template) > 0 {
format = "template"
} else {
return "", fmt.Errorf("no formatting option given")
}
f, err := DataFormat(format, template)
if err != nil {
return "", err
}
out, err := f.TransformData(data)
if err != nil {
return "", fmt.Errorf("Error formatting the data: %w", err)
}
return out, nil
}
func makeFuncMap() template.FuncMap {
fm := template.FuncMap{}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Pass -json or -template on the CLI command invocation
- In the calling command, default json/template from Meta flags (e.g. read f := getMeta(); ensure one of json/template is set) before calling Format
- If embedding Format in new code, provide a default format (e.g. format = "json" or table) when both options are absent
Example fix
// before
out, err := c.Format(data, false, "")
// after
jsonFlag := meta.flagJson
tmplFlag := meta.flagTemplate
if !jsonFlag && tmplFlag == "" {
jsonFlag = true // or pick a default format
}
out, err := c.Format(data, jsonFlag, tmplFlag) Defensive patterns
Strategy: validation
Validate before calling
if !json && template == "" {
return fmt.Errorf("either -json or -template must be provided")
} Prevention
- Always read json/template flags from shared Meta before calling Format
- Establish a default output format for new commands
- Add a unit test asserting Format errors clearly when both options are empty
When it happens
Trigger: Calling command.Format(data, false, "") — i.e. json=false and template empty — with no fallback format set before the if/else chain in Format.
Common situations: A caller (Run, multiregionPlan, checkUpgrade, csiFormatPlugin[s], ouputClaims) forgets to read the json/template flags from the CLI meta, or wires up a new command passing zero-value booleans/strings for both options.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- both -n and -c set
- evaluation ID or filter flag required
- Identifier must contain at least two characters.
- expected 1 argument, got %v
- cannot give both an address and id
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/49ee5361bcbb210c.
Report an issue: GitHub.