{"record":{"id":"23ba4d7c3fd9ae16","repo":"hashicorp/nomad","slug":"operator-q-requires-an-rtarget","errorCode":null,"errorMessage":"Operator %q requires an RTarget","messagePattern":"Operator %q requires an RTarget","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":10100,"sourceCode":"\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Semver constraint is invalid: %v\", err))\n\t\t}\n\tcase ConstraintDistinctProperty:\n\t\t// If a count is set, make sure it is convertible to a uint64\n\t\tif c.RTarget != \"\" {\n\t\t\tcount, err := strconv.ParseUint(c.RTarget, 10, 64)\n\t\t\tif err != nil {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Failed to convert RTarget %q to uint64: %v\", c.RTarget, err))\n\t\t\t} else if count < 1 {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Distinct Property must have an allowed count of 1 or greater: %d < 1\", count))\n\t\t\t}\n\t\t}\n\tcase ConstraintAttributeIsSet, ConstraintAttributeIsNotSet:\n\t\tif c.RTarget != \"\" {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Operator %q does not support an RTarget\", c.Operand))\n\t\t}\n\tcase \"=\", \"==\", \"is\", \"!=\", \"not\", \"<\", \"<=\", \">\", \">=\":\n\t\tif c.RTarget == \"\" {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Operator %q requires an RTarget\", c.Operand))\n\t\t}\n\tdefault:\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Unknown constraint type %q\", c.Operand))\n\t}\n\n\t// If the constraint must have a \"LTarget\" (attribute in the job spec), then\n\t// ensure it is not an empty string and is valid.\n\tif requireLtarget {\n\t\tif c.LTarget == \"\" {\n\t\t\tmErr.Errors = append(mErr.Errors, errors.New(\"no attribute provided but is required by operator\"))\n\t\t} else {\n\t\t\tif err := validateConstraintAttribute(c.LTarget); err != nil {\n\t\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t\t}\n\t\t}\n\n\t}\n","sourceCodeStart":10082,"sourceCodeEnd":10118,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L10082-L10118","documentation":"The constraint uses a comparison operator (=, ==, is, !=, not, <, <=, >, >=) but its RTarget (the value to compare the attribute against) is empty. These operators require a right-hand target, so validation rejects the job.","triggerScenarios":"Submitting a constraint such as constraint { attribute = \"${attr.kernel.name}\" operand = \"=\" } with no value/RTarget supplied.","commonSituations":"HCL job spec missing the value field; templated generation where the variable interpolated into value was empty; accidental whitespace-only value trimmed away; copy-paste dropping the value line.","solutions":["Add the missing value field to the constraint, e.g. value = \"linux\".","Check that any variable interpolated into value is non-empty at render time.","If no comparison is intended, switch the operand to is_set / is_not_set (which need no value)."],"exampleFix":"// before\nconstraint {\n  attribute = \"${attr.kernel.name}\"\n  operand   = \"==\"\n}\n// after\nconstraint {\n  attribute = \"${attr.kernel.name}\"\n  operand   = \"==\"\n  value     = \"linux\"\n}","handlingStrategy":"validation","validationCode":"func constraintRequiresTarget(operand, rtarget string) bool {\n  switch operand {\n  case \"=\", \"==\", \"is\", \"!=\", \"not\", \"<\", \"<=\", \">\", \">=\":\n    return rtarget != \"\"\n  default:\n    return true\n  }\n}","typeGuard":null,"tryCatchPattern":"requires := []string{\"=\", \"==\", \"is\", \"!=\", \"not\", \"<\", \"<=\", \">\", \">=\"}\nif slices.Contains(requires, operand) && rtarget == \"\" {\n  return fmt.Errorf(\"operator %q requires a value\", operand)\n}","preventionTips":["Always pair comparison operands with an explicit value field.","Interpolate variables into value only after checking they are non-empty.","Use is_set when only presence matters."],"tags":["nomad","constraint","missing-value","job-validation"],"backgroundTag":"missing-required-argument","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"}