hashicorp/nomad · error

Error formatting host volume: %w

Error message

Error formatting host volume: %w

What it means

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.

Source

Thrown at command/volume_status_host.go:51

	if err != nil {
		return fmt.Errorf("%w: %w", hostVolumeListError, err)
	}
	if len(possible) > 0 {
		out, err := formatHostVolumes(possible, opts)
		if err != nil {
			return fmt.Errorf("Error formatting: %w", err)
		}
		return fmt.Errorf("Prefix matched multiple host volumes\n\n%s", out)
	}

	vol, _, err := client.HostVolumes().Get(volStub.ID, nil)
	if err != nil {
		return fmt.Errorf("Error querying host volume: %w", err)
	}

	str, err := formatHostVolume(vol, opts)
	if err != nil {
		return fmt.Errorf("Error formatting host volume: %w", err)
	}
	c.Ui.Output(c.Colorize().Color(str))
	return nil
}

func (c *VolumeStatusCommand) hostVolumeList(client *api.Client, nodeID, nodePool string, opts formatOpts) error {
	if !(opts.json || len(opts.template) > 0) {
		c.Ui.Output(c.Colorize().Color("[bold]Dynamic Host Volumes[reset]"))
	}

	vols, _, err := client.HostVolumes().List(&api.HostVolumeListRequest{
		NodeID:   nodeID,
		NodePool: nodePool,
	}, nil)
	if err != nil {
		return fmt.Errorf("Error querying host volumes: %w", err)
	}
	if len(vols) == 0 {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Correct the -template to use real api.HostVolume fields or drop it for default table output
  2. Pass only one of -json/-template
  3. Check the wrapped error for parse-vs-execute template failure

Example fix

// before
nomad volume status -template '{{.Path}}' host myvol
// after
nomad volume status -template '{{.ID}}: {{.Name}}' host myvol
Defensive patterns

Strategy: validation

Validate before calling

if opts.template != "" { if _, err := template.New("hv").Parse(opts.template); err != nil { return err } }
if opts.json && opts.template != "" { return errors.New("-json and -template are mutually exclusive") }

Type guard

func validHostVolumeTemplate(t string) bool { if t == "" { return true }; _, err := template.New("hv").Parse(t); return err == nil }

Try / catch

str, err := formatHostVolume(vol, opts)
if err != nil {
    if strings.HasPrefix(err.Error(), "Error formatting host volume") { /* fall back to default table output */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: Copy-pasted templates using wrong field names (e.g. .HostPath instead of the actual HostVolume fields); malformed template braces; combining output flags.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/7799ee2dc2be2150. Report an issue: GitHub.