hashicorp/nomad · error
Error formatting the data: %w
Error message
Error formatting the data: %w
What it means
After Format successfully resolves a DataFormat, it applies f.TransformData(data) to render the output. If rendering fails (bad Go template syntax, unknown template function, or JSON marshaling problems), the underlying error is wrapped as "Error formatting the data: %w".
Source
Thrown at command/data_format.go:97
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{}
// Add the Sprig functions to the funcmap. These functions are decorated
// with `sprig_` to match how they are treated in consul-template
for k, v := range sprig.FuncMap() {
target := "sprig_" + k
fm[target] = v
}
return fm
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Read the wrapped cause after the colon and fix the template syntax/function name accordingly
- Validate the template with `nomad job inspect -t '<template>'` or `go template` parse locally before scripting against it
- Switch to -json output and post-process with jq if the template keeps failing
Example fix
// before
nomad status -t '{{.JobIDX}}' <id>
// after
nomad status -t '{{ range . }}{{ .ID }}{{ end }}' <id> Defensive patterns
Strategy: try-catch
Validate before calling
// parse the template first in tests:
if _, err := template.New("t").Funcs(makeFuncMap()).Parse(tmpl); err != nil {
return err
} Try / catch
out, err := Format(data, json, tmpl)
if err != nil {
var wf interface{ Unwrap() error }
if errors.As(err, &target) { /* inspect wrapped cause */ }
return fmt.Errorf("check -template syntax: %w", err)
} Prevention
- Test templates against sample JSON before using them in scripts
- Only use functions present in makeFuncMap
- Prefer -json + jq for complex transformations
When it happens
Trigger: Calling Format with template=true path where the -template string is invalid Go template syntax, references an undefined function, or the data cannot be transformed by the json/templating backend.
Common situations: Users hand-write go template strings with typos (e.g. {{.Job.IDX}}), use a sprig/template function name that isn't in makeFuncMap, or pipe output where the data shape differs from what the template expects.
Related errors
- not a terminal
- both -n and -c set
- Allocation %q is running the following tasks: * %s Please
- Region not found
- evaluation ID or filter flag required
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/aafd21ba57f7a488.
Report an issue: GitHub.