hashicorp/nomad · error

format error: %w

Error message

format error: %w

What it means

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.

Source

Thrown at command/volume_status_csi.go:148

				break
			}
			// we can't know the shape of arbitrarily-sized lists of volumes,
			// so break after each page
			c.Ui.Output("...")
		}
	}

	return mErr.ErrorOrNil()
}

func csiFormatVolumes(vols []*api.CSIVolumeListStub, json bool, template string) (string, error) {
	// Sort the output by volume id
	sort.Slice(vols, func(i, j int) bool { return vols[i].ID < vols[j].ID })

	if json || len(template) > 0 {
		out, err := Format(json, template, vols)
		if err != nil {
			return "", fmt.Errorf("format error: %w", err)
		}
		return out, nil
	}

	return csiFormatSortedVolumes(vols)
}

// Format the volumes, assumes that we're already sorted by volume ID
func csiFormatSortedVolumes(vols []*api.CSIVolumeListStub) (string, error) {
	rows := make([]string, len(vols)+1)
	rows[0] = "ID|Name|Namespace|Plugin ID|Schedulable|Access Mode"
	for i, v := range vols {
		rows[i+1] = fmt.Sprintf("%s|%s|%s|%s|%t|%s",
			v.ID,
			v.Name,
			v.Namespace,
			v.PluginID,
			v.Schedulable,

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Validate the Go template against api.CSIVolumeListStub fields (e.g. ID, Name, SchedulerName)
  2. Drop either -json or -template so only one output mode is set
  3. Consult the wrapped error text for the precise parse/execute failure

Example fix

// before
-template '{{.ControllerRequired}}'  # wrong: field is on full volume, not stub
// after
-template '{{range .}}{{.ID}} ctrl={{.ControllersHealthy}}{{end}}'
Defensive patterns

Strategy: validation

Validate before calling

t, err := template.New("vols").Parse(userTemplate)
if err != nil || (jsonFlag && userTemplate != "") { /* reject before invoking */ }

Type guard

func safeFormatOpts(json bool, tmpl string) bool { return !(json && tmpl != "") && (tmpl == "" || templateParseOK(tmpl)) }

Try / catch

out, err := run()
if err != nil && strings.HasPrefix(err.Error(), "format error") { /* fix template, data fetch was fine */ }

Prevention

When it happens

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

Common situations: Typo'd template fields on the CSIVolumeListStub shape; combining -json and -template flags; copy-pasted templates from docs for a different object type.

Related errors


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