hashicorp/nomad · error

cores value (%d) cannot be negative

Error message

cores value (%d) cannot be negative

What it means

Resources.Validate: the task requested a negative number of CPU cores (cores < 0). Nomad accepts cores = 0 (unset) or a positive count, so any negative value is appended to the multierror list.

Source

Thrown at nomad/structs/structs.go:2428

func (r *Resources) DiskInBytes() int64 {
	return int64(r.DiskMB * BytesInMegabyte)
}

const (
	// MemoryNoLimit is a sentinel value indicating there is no upper hard
	// memory limit
	MemoryNoLimit = -1
)

func (r *Resources) Validate() error {
	var mErr multierror.Error

	if r.Cores > 0 && r.CPU > 0 {
		mErr.Errors = append(mErr.Errors, errors.New("Task can only ask for 'cpu' or 'cores' resource, not both."))
	}

	if r.Cores < 0 {
		mErr.Errors = append(mErr.Errors, fmt.Errorf("cores value (%d) cannot be negative", r.Cores))
	}

	if err := r.MeetsMinResources(); err != nil {
		mErr.Errors = append(mErr.Errors, err)
	}

	// Ensure the task isn't asking for disk resources
	if r.DiskMB > 0 {
		mErr.Errors = append(mErr.Errors, errors.New("Task can't ask for disk resources, they have to be specified at the task group level."))
	}

	// Ensure devices are valid
	devices := set.New[string](len(r.Devices))
	for i, d := range r.Devices {
		if err := d.Validate(); err != nil {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("device %d failed validation: %v", i+1, err))
		}
		devices.Insert(d.Name)

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Set cores to a positive integer or remove it (use cpu instead)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at nomad/structs/structs.go:2428 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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