crowdsecurity/crowdsec · error

failed to parse constraint '%s'

Error message

failed to parse constraint '%s'

What it means

Returned by constraint.Satisfies when the constraint string itself cannot be parsed by hashicorp/go-version. The constraint constants (like Acquis = ">= 1.0, < 2.0") are normally hardcoded, so a failure usually means code or config supplied a bad constraint expression.

Source

Thrown at pkg/cwversion/constraint/constraint.go:24

	goversion "github.com/hashicorp/go-version"
)

const (
	Parser   = ">= 1.0, <= 3.0"
	Scenario = ">= 1.0, <= 3.0"
	API      = "v1"
	Acquis   = ">= 1.0, < 2.0"
)

func Satisfies(strvers string, constraint string) (bool, error) {
	vers, err := goversion.NewVersion(strvers)
	if err != nil {
		return false, fmt.Errorf("failed to parse '%s': %w", strvers, err)
	}

	constraints, err := goversion.NewConstraint(constraint)
	if err != nil {
		return false, fmt.Errorf("failed to parse constraint '%s'", constraint)
	}

	if !constraints.Check(vers) {
		return false, nil
	}

	return true, nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Inspect the constraint string in the error and correct its syntax to go-version format (e.g. '>= 1.0, < 2.0').
  2. Re-download the hub index (cscli hub update) if the constraint came from hub metadata.
  3. Update crowdsec if the constraint constant in your binary is outdated/incorrect.
  4. For developers: validate constraints against goversion.NewConstraint in tests.

Example fix

// before
constraint.Satisfies(v, "1.0 - 2.0")
// after
constraint.Satisfies(v, ">= 1.0, < 2.0")
Defensive patterns

Strategy: validation

Validate before calling

if _, err := goversion.NewConstraint(constraintStr); err != nil {
    return fmt.Errorf("constraint %q invalid: %w", constraintStr, err)
}

Try / catch

ok, err := constraint.Satisfies(v, c)
if err != nil {
    return fmt.Errorf("constraint check failed: %w", err)
}
if !ok { return ErrIncompatible }

Prevention

When it happens

Trigger: loadBucketFactoriesFromFile or processStageFile invokes Satisfies with a constraint built from config/file data that is empty or not a valid go-version constraint (e.g. missing comparison operator, stray comma).

Common situations: Custom item metadata with a malformed 'supported_versions' style field, corrupted hub index, or a code-level typo in a new constraint constant.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/4dd4f643a56c9970. Report an issue: GitHub.