{"record":{"id":"7799ee2dc2be2150","repo":"hashicorp/nomad","slug":"error-formatting-host-volume-w","errorCode":null,"errorMessage":"Error formatting host volume: %w","messagePattern":"Error formatting host volume: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/volume_status_host.go","lineNumber":51,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"%w: %w\", hostVolumeListError, err)\n\t}\n\tif len(possible) > 0 {\n\t\tout, err := formatHostVolumes(possible, opts)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error formatting: %w\", err)\n\t\t}\n\t\treturn fmt.Errorf(\"Prefix matched multiple host volumes\\n\\n%s\", out)\n\t}\n\n\tvol, _, err := client.HostVolumes().Get(volStub.ID, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error querying host volume: %w\", err)\n\t}\n\n\tstr, err := formatHostVolume(vol, opts)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error formatting host volume: %w\", err)\n\t}\n\tc.Ui.Output(c.Colorize().Color(str))\n\treturn nil\n}\n\nfunc (c *VolumeStatusCommand) hostVolumeList(client *api.Client, nodeID, nodePool string, opts formatOpts) error {\n\tif !(opts.json || len(opts.template) > 0) {\n\t\tc.Ui.Output(c.Colorize().Color(\"[bold]Dynamic Host Volumes[reset]\"))\n\t}\n\n\tvols, _, err := client.HostVolumes().List(&api.HostVolumeListRequest{\n\t\tNodeID:   nodeID,\n\t\tNodePool: nodePool,\n\t}, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error querying host volumes: %w\", err)\n\t}\n\tif len(vols) == 0 {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/volume_status_host.go#L33-L69","documentation":"hostVolumeStatus wraps failures from formatHostVolume when rendering the successfully fetched single host volume (table or JSON/template). Data retrieval succeeded; only output formatting failed, with the cause wrapped via %w.","triggerScenarios":"After a successful HostVolumes().Get, formatHostVolume(vol, opts) returns an error — typically an invalid Go -template, -json combined with -template, or template referencing fields absent from api.HostVolume.","commonSituations":"Copy-pasted templates using wrong field names (e.g. .HostPath instead of the actual HostVolume fields); malformed template braces; combining output flags.","solutions":["Correct the -template to use real api.HostVolume fields or drop it for default table output","Pass only one of -json/-template","Check the wrapped error for parse-vs-execute template failure"],"exampleFix":"// before\nnomad volume status -template '{{.Path}}' host myvol\n// after\nnomad volume status -template '{{.ID}}: {{.Name}}' host myvol","handlingStrategy":"validation","validationCode":"if opts.template != \"\" { if _, err := template.New(\"hv\").Parse(opts.template); err != nil { return err } }\nif opts.json && opts.template != \"\" { return errors.New(\"-json and -template are mutually exclusive\") }","typeGuard":"func validHostVolumeTemplate(t string) bool { if t == \"\" { return true }; _, err := template.New(\"hv\").Parse(t); return err == nil }","tryCatchPattern":"str, err := formatHostVolume(vol, opts)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"Error formatting host volume\") { /* fall back to default table output */ }\n}","preventionTips":["Parse templates up front; fail fast at flag processing","Use fields from api.HostVolume only","Avoid combining -json and -template; prefer default output when scripting"],"tags":["cli","formatting","template","host-volumes"],"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"}