hashicorp/nomad · error
Failed to convert RTarget %q to uint64: %v
Error message
Failed to convert RTarget %q to uint64: %v
What it means
A "distinct_property" constraint's RTarget (the allowed count) was set but could not be parsed as an unsigned 64-bit integer via strconv.ParseUint. The count must be a plain non-negative integer string. The job fails validation and is rejected by the Nomad API.
Source
Thrown at nomad/structs/structs.go:10089
}
case ConstraintRegex:
if _, err := regexp.Compile(c.RTarget); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Regular expression failed to compile: %v", err))
}
case ConstraintVersion:
if _, err := version.NewConstraint(c.RTarget); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Version constraint is invalid: %v", err))
}
case ConstraintSemver:
if _, err := semver.NewConstraint(c.RTarget); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Semver constraint is invalid: %v", err))
}
case ConstraintDistinctProperty:
// If a count is set, make sure it is convertible to a uint64
if c.RTarget != "" {
count, err := strconv.ParseUint(c.RTarget, 10, 64)
if err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Failed to convert RTarget %q to uint64: %v", c.RTarget, err))
} else if count < 1 {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Distinct Property must have an allowed count of 1 or greater: %d < 1", count))
}
}
case ConstraintAttributeIsSet, ConstraintAttributeIsNotSet:
if c.RTarget != "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Operator %q does not support an RTarget", c.Operand))
}
case "=", "==", "is", "!=", "not", "<", "<=", ">", ">=":
if c.RTarget == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Operator %q requires an RTarget", c.Operand))
}
default:
mErr.Errors = append(mErr.Errors, fmt.Errorf("Unknown constraint type %q", c.Operand))
}
// If the constraint must have a "LTarget" (attribute in the job spec), then
// ensure it is not an empty string and is valid.View on GitHub (pinned to 482b49bf1a)
Solutions
- Set the distinct_property count RTarget to a plain decimal integer string, e.g. "2".
- Ensure the value has no sign, decimals, whitespace, or separators.
- Pre-validate with strconv.ParseUint(target, 10, 64) before submitting.
Example fix
// before
constraint {
attribute = "${attr.datacenter}"
distinct_property = "2.0"
}
// after
constraint {
attribute = "${attr.datacenter}"
distinct_property = "2"
} Defensive patterns
Strategy: validation
Validate before calling
func validDistinctPropertyCount(target string) bool {
if target == "" { return true }
_, err := strconv.ParseUint(target, 10, 64)
return err == nil
} Try / catch
count, err := strconv.ParseUint(target, 10, 64)
if err != nil {
return fmt.Errorf("distinct_property count must be a plain integer, got %q", target)
} Prevention
- Emit counts as integer strings ("2") from templates, never floats or signed numbers.
- Strip whitespace before submitting.
- Add a schema check on the job-rendering side.
When it happens
Trigger: Submitting a job with constraint operand "distinct_property" and RTarget values like "two", "2.0", "-1", "+3", "0x2", or a value with whitespace.
Common situations: Quoting/escaping issues in HCL producing a non-numeric string; passing a float or negative count from templated job generation; copying examples that use a number literal where a string "2" is expected; locale-formatted numbers with thousand separators.
Related errors
- Distinct Property must have an allowed count of 1 or greater
- users: unable to parse uid/gid from username
- <combined HCL diagnostics from str.String()>
- Missing constraint operand
- no attribute provided but is required by operator
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/ccdadc54d2cc5066.
Report an issue: GitHub.