{"record":{"id":"5020d5acd19727a1","repo":"hashicorp/nomad","slug":"invalid-constraint-v-5020d5","errorCode":null,"errorMessage":"invalid constraint: %v","messagePattern":"invalid constraint: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/host_volumes.go","lineNumber":160,"sourceCode":"\t\tmErr = multierror.Append(mErr, errors.New(\"missing name\"))\n\t}\n\n\tif hv.RequestedCapacityMaxBytes < hv.RequestedCapacityMinBytes {\n\t\tmErr = multierror.Append(mErr, fmt.Errorf(\n\t\t\t\"capacity_max (%d) must be larger than capacity_min (%d)\",\n\t\t\thv.RequestedCapacityMaxBytes, hv.RequestedCapacityMinBytes))\n\t}\n\n\tfor _, cap := range hv.RequestedCapabilities {\n\t\terr := cap.Validate()\n\t\tif err != nil {\n\t\t\tmErr = multierror.Append(mErr, err)\n\t\t}\n\t}\n\n\tfor _, constraint := range hv.Constraints {\n\t\tif err := constraint.Validate(); err != nil {\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"invalid constraint: %v\", err))\n\t\t}\n\t\tswitch constraint.Operand {\n\t\tcase ConstraintDistinctHosts, ConstraintDistinctProperty:\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\n\t\t\t\t\"invalid constraint %s: host volumes of the same name are always on distinct hosts\", constraint.Operand))\n\t\tdefault:\n\t\t}\n\t}\n\n\treturn helper.FlattenMultierror(mErr.ErrorOrNil())\n}\n\n// ValidateUpdate verifies that an update to a volume is safe to make.\nfunc (hv *HostVolume) ValidateUpdate(existing *HostVolume) error {\n\tif existing == nil {\n\t\treturn nil\n\t}\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/host_volumes.go#L142-L178","documentation":"Each constraint on a host volume must pass Constraint.Validate; failures are wrapped as 'invalid constraint: %v'. Additionally, distinct_hosts and distinct_property operands are rejected outright because host volumes of the same name are always placed on distinct hosts by construction.","triggerScenarios":"Registering a host volume with a malformed constraint (missing operand/target, bad LTarget/RTarget) or with operand distinct_hosts / distinct_property set.","commonSituations":"Copying job-level constraints onto host volumes without realizing some operands are unsupported there, typos in operand names, or incomplete constraint objects from API clients.","solutions":["Remove distinct_hosts/distinct_property constraints from the volume","Fix the constraint fields (operand, LTarget, RTarget) so constraint.Validate() passes","Use supported operands only (e.g. attribute comparisons)"],"exampleFix":"// before\nconstraints { attribute = \"${node.unique.id}\"; operand = \"distinct_hosts\" }\n// after\nconstraints { attribute = \"${attr.kernel.name}\"; operand = \"=\"; value = \"linux\" }","handlingStrategy":"validation","validationCode":"for _, c := range hv.Constraints {\n  if err := c.Validate(); err != nil { return err }\n  if c.Operand == structs.ConstraintDistinctHosts || c.Operand == structs.ConstraintDistinctProperty {\n    return fmt.Errorf(\"operand %s unsupported on host volumes\", c.Operand)\n  }\n}","typeGuard":null,"tryCatchPattern":"if err := hv.Validate(); err != nil {\n  return fmt.Errorf(\"fix volume constraints: %w\", err)\n}","preventionTips":["Don't copy job-level constraints onto host volumes","Avoid distinct_hosts/distinct_property on volumes","Validate constraints in client code before registration"],"tags":["nomad","host-volumes","validation","constraints"],"backgroundTag":"invalid-constraint","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"}