hashicorp/nomad · error

missing device name

Error message

missing device name

What it means

In parseDeviceResource each item of the quota's `device` block must be a keyed entry where the key is the device name. An entry with zero keys (e.g. a bare block with no name) produces "missing device name", prefixed as `resources, device[N]->` so the index of the offending entry is known. It is HCL structure validation for `nomad quota apply`.

Source

Thrown at command/quota_apply.go:380

	case string:
		b, err := humanize.ParseBytes(val)
		if err != nil {
			return 0, fmt.Errorf("could not parse value as bytes: %v", err)
		}
		return int(b >> 20), nil
	case int:
		return val, nil
	case nil:
		return 0, nil
	default:
		return 0, fmt.Errorf("invalid type %T", raw)
	}
}

func parseDeviceResource(result *[]*api.RequestedDevice, list *ast.ObjectList) error {
	for idx, o := range list.Items {
		if l := len(o.Keys); l == 0 {
			return multierror.Prefix(fmt.Errorf("missing device name"), fmt.Sprintf("resources, device[%d]->", idx))
		} else if l > 1 {
			return multierror.Prefix(fmt.Errorf("only one name may be specified"), fmt.Sprintf("resources, device[%d]->", idx))
		}

		name := o.Keys[0].Token.Value().(string)

		// Check for invalid keys
		valid := []string{
			"name",
			"count",
		}
		if err := helper.CheckHCLKeys(o.Val, valid); err != nil {
			return err
		}

		// Set the name
		var device api.RequestedDevice
		device.Name = name

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Give every device entry exactly one name key, e.g. `device "nvidia/gpu" { count = 2 }`.
  2. Locate the entry via the `device[N]` prefix in the error (zero-based index) and fix that specific stanza.
  3. Compare against valid quota examples in the Nomad docs for the device block syntax.
  4. Run the file through HCL validation (`hclfmt`/lint) to catch anonymous blocks.

Example fix

// before
device {
  count = 1
}
// after
device "nvidia/gpu" {
  count = 1
}
Defensive patterns

Strategy: validation

Validate before calling

// Check every device entry has exactly one key before parsing
for idx, item := range deviceList.Items {
    if len(item.Keys) == 0 {
        return fmt.Errorf("resources, device[%d]-> missing device name", idx)
    }
}

Type guard

func hasNameKey(item *hclast.ObjectItem) bool {
    return item != nil && len(item.Keys) == 1
}

Prevention

When it happens

Trigger: A quota file contains a device entry written without a name key, e.g. an anonymous `device { ... }` block or a list element missing its label, inside the resources stanza of the quota spec.

Common situations: Copy-pasting job-spec device syntax into a quota file where a named key is required; hand-editing HCL and deleting the name by accident; converting JSON to HCL and dropping the object key.

Related errors


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