{"record":{"id":"1bdecb91f1fdcbaf","repo":"hashicorp/nomad","slug":"limit-must-be-greater-than-or-equal-to-0-but-found","errorCode":null,"errorMessage":"limit must be greater than or equal to 0 but found %d","messagePattern":"limit must be greater than or equal to 0 but found (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7826,"sourceCode":"\tif c.Grace != o.Grace {\n\t\treturn false\n\t}\n\n\tif c.IgnoreWarnings != o.IgnoreWarnings {\n\t\treturn false\n\t}\n\n\treturn true\n}\n\nfunc (c *CheckRestart) Validate() error {\n\tif c == nil {\n\t\treturn nil\n\t}\n\n\tvar mErr multierror.Error\n\tif c.Limit < 0 {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"limit must be greater than or equal to 0 but found %d\", c.Limit))\n\t}\n\n\tif c.Grace < 0 {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"grace period must be greater than or equal to 0 but found %d\", c.Grace))\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\nconst (\n\t// DefaultKillTimeout is the default timeout between signaling a task it\n\t// will be killed and killing it.\n\tDefaultKillTimeout = 5 * time.Second\n)\n\n// LogConfig provides configuration for log rotation\ntype LogConfig struct {\n\tMaxFiles      int","sourceCodeStart":7808,"sourceCodeEnd":7844,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7808-L7844","documentation":"CheckRestart.Validate() rejects a negative `limit` value. `limit` bounds how many restarts the check restart policy allows, so it must be >= 0 (0 meaning unlimited/none per semantics); a negative value is always a config mistake.","triggerScenarios":"Submitting a job with a `check_restart { limit = -N }` block (or CheckRestart struct with Limit < 0) on a service check.","commonSituations":"Templating limit from an environment variable/parameter that is unset or negative; typos like `limit = -1`; arithmetic producing negative defaults.","solutions":["Set `limit` to a non-negative integer (e.g. 1-3)","Remove the `limit` field to use the default","Clamp/validate the value in your templating layer before rendering HCL"],"exampleFix":"// before\ncheck_restart { limit = -1 }\n// after\ncheck_restart { limit = 3 }","handlingStrategy":"validation","validationCode":"if cr != nil && cr.Limit < 0 {\n  return fmt.Errorf(\"check_restart.limit must be >= 0, got %d\", cr.Limit)\n}","typeGuard":"func validCheckRestart(cr *api.CheckRestart) bool {\n  return cr == nil || (cr.Limit >= 0 && cr.Grace >= 0)\n}","tryCatchPattern":null,"preventionTips":["Clamp templated limit values: if v < 0 { v = 0 }","Default limit via omitted field instead of explicit negatives","Unit-test job-rendering code with edge-case inputs"],"tags":["nomad","check-restart","job-validation"],"backgroundTag":"invalid-argument-value","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"}