{"record":{"id":"19fef43d6d05b0e6","repo":"hashicorp/nomad","slug":"cores-value-d-cannot-be-negative","errorCode":null,"errorMessage":"cores value (%d) cannot be negative","messagePattern":"cores value \\((.+?)\\) cannot be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":2428,"sourceCode":"func (r *Resources) DiskInBytes() int64 {\n\treturn int64(r.DiskMB * BytesInMegabyte)\n}\n\nconst (\n\t// MemoryNoLimit is a sentinel value indicating there is no upper hard\n\t// memory limit\n\tMemoryNoLimit = -1\n)\n\nfunc (r *Resources) Validate() error {\n\tvar mErr multierror.Error\n\n\tif r.Cores > 0 && r.CPU > 0 {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Task can only ask for 'cpu' or 'cores' resource, not both.\"))\n\t}\n\n\tif r.Cores < 0 {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"cores value (%d) cannot be negative\", r.Cores))\n\t}\n\n\tif err := r.MeetsMinResources(); err != nil {\n\t\tmErr.Errors = append(mErr.Errors, err)\n\t}\n\n\t// Ensure the task isn't asking for disk resources\n\tif r.DiskMB > 0 {\n\t\tmErr.Errors = append(mErr.Errors, errors.New(\"Task can't ask for disk resources, they have to be specified at the task group level.\"))\n\t}\n\n\t// Ensure devices are valid\n\tdevices := set.New[string](len(r.Devices))\n\tfor i, d := range r.Devices {\n\t\tif err := d.Validate(); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"device %d failed validation: %v\", i+1, err))\n\t\t}\n\t\tdevices.Insert(d.Name)","sourceCodeStart":2410,"sourceCodeEnd":2446,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L2410-L2446","documentation":"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.","triggerScenarios":"Thrown at nomad/structs/structs.go:2428 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set cores to a positive integer or remove it (use cpu instead)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}