hashicorp/nomad · error

dispatch error: %v

Error message

dispatch error: %v

What it means

After parsing the AST, parseVolumeType decodes only the top-level `type` field into a dispatch struct via hcl.DecodeObject. If decoding fails — wrong types, malformed structure incompatible with the hcl tag — the error is wrapped as `dispatch error: %v`. This happens after successful parse, so the input is syntactically valid HCL.

Source

Thrown at command/volume_register.go:148

		return 1
	}
}

// parseVolume is used to parse the quota specification from HCL
func parseVolumeType(input string) (*ast.File, string, error) {
	// Parse the AST first
	ast, err := hcl.Parse(input)
	if err != nil {
		return nil, "", fmt.Errorf("parse error: %v", err)
	}

	// Decode the type, so we can dispatch on it
	dispatch := &struct {
		T string `hcl:"type"`
	}{}
	err = hcl.DecodeObject(dispatch, ast)
	if err != nil {
		return nil, "", fmt.Errorf("dispatch error: %v", err)
	}

	return ast, dispatch.T, nil
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Set `type` as a top-level string attribute: `type = "host"` or `type = "csi"`
  2. Read the inner error after `dispatch error:` for the decode mismatch
  3. Quote the value if it's unquoted, and avoid assigning lists/numbers to type
  4. Check the file was parsed with the intended HCL dialect (no stray JSON keys)

Example fix

// before
type = 2

// after
type = "csi"
Defensive patterns

Strategy: validation

Validate before calling

func validateVolumeType(input string) (string, error) {
	a, err := hcl.Parse(input)
	if err != nil {
		return "", err
	}
	d := &struct {
		T string `hcl:"type"`
	}{}
	if err := hcl.DecodeObject(d, a); err != nil {
		return "", fmt.Errorf("type must be a top-level string: %v", err)
	}
	if d.T != "host" && d.T != "csi" {
		return "", fmt.Errorf("unsupported volume type %q", d.T)
	}
	return d.T, nil
}

Try / catch

_, typ, err := parseVolumeType(input)
if err != nil && strings.HasPrefix(err.Error(), "dispatch error:") {
	return fmt.Errorf("ensure `type = \"host\"` (string) at the top level of the spec: %v", err)
}

Prevention

When it happens

Trigger: `nomad volume register` with a syntactically valid HCL file where the `type` attribute has a non-string value (e.g. `type = 2` or `type = ["host"]`), or the root structure can't be decoded into the dispatch struct.

Common situations: Quoting mistakes that make type a list or number; shadowing `type` inside a nested block and expecting the top-level dispatch to find it; using an HCL dialect feature (heredoc, function call) that decodes to an unexpected type.

Related errors


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