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

  1. Set the distinct_property count RTarget to a plain decimal integer string, e.g. "2".
  2. Ensure the value has no sign, decimals, whitespace, or separators.
  3. 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

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


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/ccdadc54d2cc5066. Report an issue: GitHub.