{"record":{"id":"fb63b6f7a8457525","repo":"hashicorp/nomad","slug":"minimum-count-must-be-specified-and-non-negative","errorCode":null,"errorMessage":"minimum count must be specified and non-negative","messagePattern":"minimum count must be specified and non-negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":6452,"sourceCode":"\t// Check policy type and target\n\tif p.Type == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"missing scaling policy type\"))\n\t} else {\n\t\tmErr.Errors = append(mErr.Errors, p.validateType().Errors...)\n\t}\n\n\t// Check Min and Max\n\tif p.Max < 0 {\n\t\tmErr.Errors = append(mErr.Errors,\n\t\t\tfmt.Errorf(\"maximum count must be specified and non-negative\"))\n\t} else if p.Max < p.Min {\n\t\tmErr.Errors = append(mErr.Errors,\n\t\t\tfmt.Errorf(\"maximum count must not be less than minimum count\"))\n\t}\n\n\tif p.Min < 0 {\n\t\tmErr.Errors = append(mErr.Errors,\n\t\t\tfmt.Errorf(\"minimum count must be specified and non-negative\"))\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\nfunc (p *ScalingPolicy) validateTargetHorizontal() (mErr multierror.Error) {\n\tif len(p.Target) == 0 {\n\t\t// This is probably not a Nomad horizontal policy\n\t\treturn\n\t}\n\n\t// Nomad horizontal policies should have Namespace, Job and TaskGroup\n\tif p.Target[ScalingTargetNamespace] == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"missing target namespace\"))\n\t}\n\tif p.Target[ScalingTargetJob] == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"missing target job\"))\n\t}","sourceCodeStart":6434,"sourceCodeEnd":6470,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L6434-L6470","documentation":"ScalingPolicy.Validate() requires the `min` count to be a non-negative integer. A negative Min (e.g. the -1 'unset' sentinel) appends this error to the multierror. Min defines the lower bound of the allowed task-group count range.","triggerScenarios":"Submitting a job with `scaling { min = -1 }`, or constructing a ScalingPolicy via the API with a negative Min left from a default value.","commonSituations":"Omitting min in generated policy JSON where the struct default is negative; using -1 to mean 'no minimum' in custom tooling; typos in HCL.","solutions":["Set `min` to zero or a positive integer in the scaling block.","If you want no effective minimum, use `min = 0`, not a negative number.","Re-run `nomad job validate` to confirm the whole policy passes."],"exampleFix":"// before\nscaling {\n  min = -1\n  max = 10\n}\n// after\nscaling {\n  min = 0\n  max = 10\n}","handlingStrategy":"validation","validationCode":"if policy.Min < 0 {\n\treturn fmt.Errorf(\"scaling policy min must be non-negative; use 0 for no minimum\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default Min to 0 rather than -1 in generated policies.","Parse HCL with explicit min values; never leave them to struct zero/defaults.","Run `nomad job validate` before submission."],"tags":["nomad","scaling-policy","validation"],"backgroundTag":"invalid-numeric-range","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"}