{"record":{"id":"ec92718341e4489d","repo":"hashicorp/nomad","slug":"format-error-w","errorCode":null,"errorMessage":"format error: %w","messagePattern":"format error: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/volume_status_csi.go","lineNumber":148,"sourceCode":"\t\t\t\tbreak\n\t\t\t}\n\t\t\t// we can't know the shape of arbitrarily-sized lists of volumes,\n\t\t\t// so break after each page\n\t\t\tc.Ui.Output(\"...\")\n\t\t}\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\nfunc csiFormatVolumes(vols []*api.CSIVolumeListStub, json bool, template string) (string, error) {\n\t// Sort the output by volume id\n\tsort.Slice(vols, func(i, j int) bool { return vols[i].ID < vols[j].ID })\n\n\tif json || len(template) > 0 {\n\t\tout, err := Format(json, template, vols)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"format error: %w\", err)\n\t\t}\n\t\treturn out, nil\n\t}\n\n\treturn csiFormatSortedVolumes(vols)\n}\n\n// Format the volumes, assumes that we're already sorted by volume ID\nfunc csiFormatSortedVolumes(vols []*api.CSIVolumeListStub) (string, error) {\n\trows := make([]string, len(vols)+1)\n\trows[0] = \"ID|Name|Namespace|Plugin ID|Schedulable|Access Mode\"\n\tfor i, v := range vols {\n\t\trows[i+1] = fmt.Sprintf(\"%s|%s|%s|%s|%t|%s\",\n\t\t\tv.ID,\n\t\t\tv.Name,\n\t\t\tv.Namespace,\n\t\t\tv.PluginID,\n\t\t\tv.Schedulable,","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/volume_status_csi.go#L130-L166","documentation":"csiFormatVolumes wraps failures from the shared Format helper when rendering CSI volume stubs as JSON or via a Go template. Data was fetched fine; only the output transformation failed, and the cause is wrapped with %w.","triggerScenarios":"deleteCSIVolume, Run, csiVolumeStatus, or csiVolumesList pass json=true or a non-empty template and Format fails: invalid template syntax, -json with -template, or marshal error.","commonSituations":"Typo'd template fields on the CSIVolumeListStub shape; combining -json and -template flags; copy-pasted templates from docs for a different object type.","solutions":["Validate the Go template against api.CSIVolumeListStub fields (e.g. ID, Name, SchedulerName)","Drop either -json or -template so only one output mode is set","Consult the wrapped error text for the precise parse/execute failure"],"exampleFix":"// before\n-template '{{.ControllerRequired}}'  # wrong: field is on full volume, not stub\n// after\n-template '{{range .}}{{.ID}} ctrl={{.ControllersHealthy}}{{end}}'","handlingStrategy":"validation","validationCode":"t, err := template.New(\"vols\").Parse(userTemplate)\nif err != nil || (jsonFlag && userTemplate != \"\") { /* reject before invoking */ }","typeGuard":"func safeFormatOpts(json bool, tmpl string) bool { return !(json && tmpl != \"\") && (tmpl == \"\" || templateParseOK(tmpl)) }","tryCatchPattern":"out, err := run()\nif err != nil && strings.HasPrefix(err.Error(), \"format error\") { /* fix template, data fetch was fine */ }","preventionTips":["Validate Go template syntax before use","Keep templates minimal and field-checked against api.CSIVolumeListStub","Avoid mixing -json and -template"],"tags":["cli","formatting","template"],"backgroundTag":"template-render-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}