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
- Inspect the constraint string in the error and correct its syntax to go-version format (e.g. '>= 1.0, < 2.0').
- Re-download the hub index (cscli hub update) if the constraint came from hub metadata.
- Update crowdsec if the constraint constant in your binary is outdated/incorrect.
- 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
- Write constraints in go-version syntax: '>= 1.0, < 2.0'
- Re-fetch hub metadata if constraints come from the hub index
- Unit-test any newly introduced constraint constant
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- while syncing %s %s: %w
- failed to parse '%s': %w
- pid inside tag must be closed with ']'
- message is empty
- PRI must start with '<'
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/4dd4f643a56c9970.
Report an issue: GitHub.