{"record":{"id":"aecfe0c6043d4f60","repo":"hashicorp/nomad","slug":"failures-before-critical-must-be-non-negative","errorCode":null,"errorMessage":"failures_before_critical must be non-negative","messagePattern":"failures_before_critical must be non-negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/services.go","lineNumber":448,"sourceCode":"\t\tdefault:\n\t\t\treturn fmt.Errorf(\"expose may only be set on HTTP or gRPC checks\")\n\t\t}\n\t}\n\n\t// passFailCheckTypes are intersection of check types supported by both Consul\n\t// and Nomad when using the pass/fail check threshold features.\n\t//\n\t// Consul only.\n\tpassFailCheckTypes := []string{\"tcp\", \"http\", \"grpc\"}\n\n\tif sc.SuccessBeforePassing < 0 {\n\t\treturn fmt.Errorf(\"success_before_passing must be non-negative\")\n\t} else if sc.SuccessBeforePassing > 0 && !slices.Contains(passFailCheckTypes, sc.Type) {\n\t\treturn fmt.Errorf(\"success_before_passing not supported for check of type %q\", sc.Type)\n\t}\n\n\tif sc.FailuresBeforeCritical < 0 {\n\t\treturn fmt.Errorf(\"failures_before_critical must be non-negative\")\n\t} else if sc.FailuresBeforeCritical > 0 && !slices.Contains(passFailCheckTypes, sc.Type) {\n\t\treturn fmt.Errorf(\"failures_before_critical not supported for check of type %q\", sc.Type)\n\t}\n\n\tif sc.FailuresBeforeWarning < 0 {\n\t\treturn fmt.Errorf(\"failures_before_warning must be non-negative\")\n\t} else if sc.FailuresBeforeWarning > 0 && !slices.Contains(passFailCheckTypes, sc.Type) {\n\t\treturn fmt.Errorf(\"failures_before_warning not supported for check of type %q\", sc.Type)\n\t}\n\n\t// Arbitrary value, we could bump it if needed\n\tif len(sc.Notes) > 255 {\n\t\treturn fmt.Errorf(\"notes must not be longer than 255 characters\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/services.go#L430-L466","documentation":"Consul check validation requires FailuresBeforeCritical to be zero or positive. A negative value is nonsensical (counts of consecutive failures cannot be negative) and is rejected before any type-specific checks.","triggerScenarios":"Setting check.FailuresBeforeCritical to any negative integer (e.g. -1) in a Consul service check and validating it via validateConsul during job/service validation.","commonSituations":"HCL variable interpolation producing a negative default; arithmetic on counts gone wrong; typo like '= -1' intended as unset.","solutions":["Set failures_before_critical to 0 to disable","Use a non-negative integer equal to the desired failure threshold"],"exampleFix":"// before\ncheck {\n  failures_before_critical = -1\n}\n// after\ncheck {\n  failures_before_critical = 2\n}","handlingStrategy":"validation","validationCode":"if sc.FailuresBeforeCritical < 0 {\n    return fmt.Errorf(\"failures_before_critical must be non-negative\")\n}","typeGuard":"func validFailuresBeforeCritical(sc *ServiceCheck) bool { return sc.FailuresBeforeCritical >= 0 }","tryCatchPattern":null,"preventionTips":["Never use negative sentinels for 'unset'; use 0","Lint interpolated HCL values for sign"],"tags":["nomad","consul","service-check","validation"],"backgroundTag":"invalid-check-configuration","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"}