hashicorp/nomad · error
Regular expression failed to compile: %v
Error message
Regular expression failed to compile: %v
What it means
For operand = "regexp" the constraint's RTarget must be a valid Go regular expression. regexp.Compile is run at validation time and any compile error is surfaced as 'Regular expression failed to compile: %v'.
Source
Thrown at nomad/structs/structs.go:10074
if c.Operand == "" {
mErr.Errors = append(mErr.Errors, errors.New("Missing constraint operand"))
}
// requireLtarget specifies whether the constraint requires an LTarget to be
// provided.
requireLtarget := true
// Perform additional validation based on operand
switch c.Operand {
case ConstraintDistinctHosts:
requireLtarget = false
case ConstraintSetContainsAll, ConstraintSetContainsAny, ConstraintSetContains:
if c.RTarget == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Set contains constraint requires an RTarget"))
}
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))
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Test the pattern with Go's regexp (RE2) syntax, e.g. go run with regexp.Compile, before submitting.
- Fix common syntax errors: balance [], (), escape backslashes, avoid lookahead/lookbehind (unsupported in RE2).
- Simplify the pattern or use a version/semver constraint instead of regex where possible.
Example fix
// before
constraint {
operand = "regexp"
attribute = "${node.datacenter}"
value = "dc[1-2("
}
// after
constraint {
operand = "regexp"
attribute = "${node.datacenter}"
value = "dc[1-2]"
} Defensive patterns
Strategy: validation
Validate before calling
if _, err := regexp.Compile(value); err != nil {
return fmt.Errorf("constraint regex invalid: %v", err)
} Prevention
- Precompile patterns with Go regexp (RE2) before shipping jobs
- Avoid PCRE-only features (lookaheads, backrefs)
- Run nomad job validate in CI to catch regex errors early
When it happens
Trigger: constraint { operand = "regexp", value = "web[0-9" } — unbalanced brackets, trailing backslash, invalid repetition like '{2,1}', or unsupported syntax in the rtarget/value.
Common situations: Hand-written patterns with escaping mistakes (Windows-style backslashes); patterns copied from grep/PCRE with Go-unsupported constructs; interpolation producing malformed patterns.
Related errors
- Missing constraint operand
- no attribute provided but is required by operator
- invalid constraint: %v
- attribute %q is missing an opening brace
- attribute %q is missing a closing brace
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/7fc47c3242197eec.
Report an issue: GitHub.