{"record":{"id":"99ed4b6147fc93c2","repo":"hashicorp/nomad","slug":"constraint-d-validation-failed-s","errorCode":null,"errorMessage":"Constraint %d validation failed: %s","messagePattern":"Constraint (.+?) validation failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":3143,"sourceCode":"func (r *RequestedDevice) Validate() error {\n\tif r == nil {\n\t\treturn nil\n\t}\n\n\tvar mErr multierror.Error\n\tif r.Name == \"\" {\n\t\t_ = multierror.Append(&mErr, errors.New(\"device name must be given as one of the following: type, vendor/type, or vendor/type/name\"))\n\t}\n\n\tfor idx, constr := range r.Constraints {\n\t\t// Ensure that the constraint doesn't use an operand we do not allow\n\t\tswitch constr.Operand {\n\t\tcase ConstraintDistinctHosts, ConstraintDistinctProperty:\n\t\t\touter := fmt.Errorf(\"Constraint %d validation failed: using unsupported operand %q\", idx+1, constr.Operand)\n\t\t\t_ = multierror.Append(&mErr, outer)\n\t\tdefault:\n\t\t\tif err := constr.Validate(); err != nil {\n\t\t\t\touter := fmt.Errorf(\"Constraint %d validation failed: %s\", idx+1, err)\n\t\t\t\t_ = multierror.Append(&mErr, outer)\n\t\t\t}\n\t\t}\n\t}\n\tfor idx, affinity := range r.Affinities {\n\t\tif err := affinity.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Affinity %d validation failed: %s\", idx+1, err)\n\t\t\t_ = multierror.Append(&mErr, outer)\n\t\t}\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\n// NodeResources is used to define the resources available on a client node.\ntype NodeResources struct {\n\t// Do not read from this value except for compatibility (i.e. serialization).\n\t//","sourceCodeStart":3125,"sourceCodeEnd":3161,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L3125-L3161","documentation":"A generic wrapper raised while validating a task group's Constraints: for each constraint that fails Constraint.Validate() for any reason other than the special distinct operands, Nomad wraps the underlying error as \"Constraint %d validation failed: <reason>\" (1-indexed). The inner text explains the actual problem (missing LTarget/RTarget, unknown operand, regexp error, etc.).","triggerScenarios":"Submitting a job with a malformed constraint, e.g. operand = \"=\" with a missing RTarget, an invalid regexp operand value, or an empty attribute, via nomad job run or the jobs API.","commonSituations":"Hand-writing constraint stanzas with wrong operand names (e.g. \"equals\" instead of \"=\"); referencing node attributes that don't exist isn't caught here, but structural problems are; templating constraints dynamically and producing empty fields.","solutions":["Read the inner error after the colon to identify the exact constraint problem","Fix the constraint's operand/attribute/value to satisfy Constraint.Validate()","Run nomad job validate locally before submitting"],"exampleFix":"// before\nconstraint {\n  attribute = \"${meta.rack}\"\n  operand   = \"=\"\n  # RTarget missing\n}\n// after\nconstraint {\n  attribute = \"${meta.rack}\"\n  operand   = \"=\"\n  RTarget   = \"r1\"\n}","handlingStrategy":"validation","validationCode":"for i, c := range tg.Constraints {\n    if err := c.Validate(); err != nil {\n        return fmt.Errorf(\"constraint %d: %w\", i+1, err)\n    }\n}","typeGuard":"func hasConstraintOperands(l, op, r string) bool { return l != \"\" && op != \"\" && r != \"\" }","tryCatchPattern":null,"preventionTips":["Ensure every constraint has attribute, operand, and value as required","Use exact operand symbols (\"=\", \">\", \"regexp\", etc.)","Run nomad job validate in CI pipelines"],"tags":["nomad","constraint","validation","jobspec"],"backgroundTag":"constraint-validation-failed","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"}