{"record":{"id":"fdddabaf7be08af5","repo":"hashicorp/nomad","slug":"failures-before-warning-must-be-non-negative","errorCode":null,"errorMessage":"failures_before_warning must be non-negative","messagePattern":"failures_before_warning must be non-negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/services.go","lineNumber":454,"sourceCode":"\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\n// RequiresPort returns whether the service check requires the task has a port.\nfunc (sc *ServiceCheck) RequiresPort() bool {\n\tswitch sc.Type {\n\tcase ServiceCheckGRPC, ServiceCheckHTTP, ServiceCheckTCP:\n\t\treturn true\n\tdefault:","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/services.go#L436-L472","documentation":"validateConsul found a negative failures_before_warning value on a Consul check; warning/critical threshold counters must be non-negative integers.","triggerScenarios":"Setting check.FailuresBeforeWarning to a negative integer in a Consul service check and validating it.","commonSituations":"Negative default from variable interpolation; mistyped value; copy-paste introducing a leading minus sign.","solutions":["Set failures_before_warning to 0 or a positive integer"],"exampleFix":"// before\ncheck {\n  failures_before_warning = -2\n}\n// after\ncheck {\n  failures_before_warning = 2\n}","handlingStrategy":"validation","validationCode":"if sc.FailuresBeforeWarning < 0 {\n    return fmt.Errorf(\"failures_before_warning must be non-negative\")\n}","typeGuard":"func validFailuresBeforeWarning(sc *ServiceCheck) bool { return sc.FailuresBeforeWarning >= 0 }","tryCatchPattern":null,"preventionTips":["Use 0 to disable warning tolerance","Validate variables feeding check thresholds"],"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"}