hashicorp/nomad · error
Error formatting: %w
Error message
Error formatting: %w
What it means
When the prefix supplied to `nomad volume status` matches more than one CSI volume, the command formats the candidate list and returns it (as an error) with `Error formatting: %w` if csiFormatVolumes itself fails. Note the formatting error is distinct from the intentional 'Prefix matched multiple CSI volumes' message, which is not a real failure but disambiguation output.
Source
Thrown at command/volume_status_csi.go:37
if id == "" {
return c.csiVolumesList(client, opts)
}
// get a CSI volume that matches the given prefix or a list of all matches if an
// exact match is not found.
volStub, possible, err := getByPrefix[api.CSIVolumeListStub]("volumes", client.CSIVolumes().List,
func(vol *api.CSIVolumeListStub, prefix string) bool { return vol.ID == prefix },
&api.QueryOptions{
Prefix: id,
Namespace: c.namespace,
})
if err != nil {
return fmt.Errorf("Error listing CSI volumes: %w", err)
}
if len(possible) > 0 {
out, err := csiFormatVolumes(possible, c.json, c.template)
if err != nil {
return fmt.Errorf("Error formatting: %w", err)
}
return fmt.Errorf("Prefix matched multiple CSI volumes\n\n%s", out)
}
// Try querying the volume
vol, _, err := client.CSIVolumes().Info(volStub.ID, nil)
if err != nil {
return fmt.Errorf("Error querying CSI volume: %w", err)
}
str, err := c.formatCSIBasic(vol)
if err != nil {
return fmt.Errorf("Error formatting CSI volume: %w", err)
}
c.Ui.Output(str)
return nil
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Use a longer/volume ID prefix so exactly one volume matches, eliminating the multi-match path.
- If using -t/-json, fix the template expression (test it with a simpler field like .ID).
- List volumes first (`nomad volume status` with no argument) to get the exact ID.
Example fix
// before
nomad volume status web -t '{{.BadField}'
// after
nomad volume status 4e6c3f8a-... -t '{{.ID}} {{.Name}}' Defensive patterns
Strategy: fallback
Validate before calling
// disambiguate before asking for a single volume
possible, _ := client.CSIVolumes().List(&api.QueryOptions{Prefix: id})
if len(possible) > 1 {
for _, v := range possible { fmt.Println(v.ID) }
return fmt.Errorf("prefix %q is ambiguous; pick one ID", id)
} Try / catch
out, err := csiFormatVolumes(possible, json, tmpl)
if err != nil {
return fmt.Errorf("Error formatting: %w", err)
} Prevention
- Use full volume IDs in scripts instead of short prefixes.
- Test -t templates with simple fields before composing complex ones.
- Avoid ambiguous prefixes in automation; fail fast on len(possible) > 1.
When it happens
Trigger: `nomad volume status web` where multiple CSI volumes share the prefix `web`, and csiFormatVolumes fails (e.g. template rendering error with -t, or internal format error).
Common situations: Using a too-short ID prefix combined with `-t` templates referencing nonexistent fields; Go template syntax errors on the command line.
Related errors
- Prefix matched multiple CSI volumes %s
- error parsing: root should be an object
- invalid capacity_min: %v
- invalid capacity_max: %v
- Error formatting CSI volume: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/d311bf2d032ea9ad.
Report an issue: GitHub.