crowdsecurity/crowdsec · error
assertion '%s' is not a condition
Error message
assertion '%s' is not a condition
What it means
Run evaluates an assertion expression and expects the result to be a boolean. If the expr evaluation succeeds but the output is any other type (string, int, nil), the assertion cannot be interpreted as a pass/fail condition and this error is returned. It flags assertions written as expressions that return values rather than conditions.
Source
Thrown at pkg/hubtest/parser_assert.go:223
ret, err := yaml.Marshal(output)
if err != nil {
return "", err
}
return string(ret), nil
}
func (p *ParserAssert) Run(assert string) (bool, error) {
output, err := p.RunExpression(assert)
if err != nil {
return false, err
}
switch out := output.(type) {
case bool:
return out, nil
default:
return false, fmt.Errorf("assertion '%s' is not a condition", assert)
}
}
func Escape(val string) string {
val = strings.ReplaceAll(val, `\`, `\\`)
val = strings.ReplaceAll(val, `"`, `\"`)
return val
}
func (p *ParserAssert) AutoGenParserAssert() string {
// attempt to autogen parser asserts
ret := fmt.Sprintf("len(results) == %d\n", len(*p.TestData))
// sort map keys for consistent order
stages := maptools.SortedKeys(*p.TestData)
for _, stage := range stages {View on GitHub (pinned to 909b515798)
Solutions
- Rewrite the assertion as a boolean condition (comparison, ==, !=, and/or)
- Check that top-level expression returns bool, e.g. wrap value: Alert.GetValue() == '1.2.3.4'
- Run the expression via EvalExpression to see the actual output type
- Fix auto-generation artifacts if the assert file was machine produced
Example fix
// before Alert.GetValue() // after Alert.GetValue() == '1.2.3.4'
Defensive patterns
Strategy: validation
Validate before calling
out, err := p.RunExpression(assert)
if err != nil { return false, err }
if _, ok := out.(bool); !ok {
return false, fmt.Errorf("assertion %q must evaluate to a bool, got %T", assert, out)
} Type guard
func isBool(v interface{}) bool { _, ok := v.(bool); return ok } Try / catch
ok, err := p.Run(assertLine)
if err != nil {
if strings.Contains(err.Error(), "is not a condition") {
return fmt.Errorf("fix assertion to return a bool: %v", err)
}
return err
} Prevention
- Write assertions as full comparisons, never bare value expressions
- Check auto-generated asserts for non-bool expressions
- Run each assert through EvalExpression and assert the %T is bool in CI
When it happens
Trigger: ParserAssert.Run called (by AssertFile) with an assertion whose expression evaluates to a non-bool, e.g. `Alert.GetValue()` alone, a string literal, or a comparison chain that expr reduces to a value.
Common situations: Assert files authored with bare expressions instead of equality/comparison conditions; auto-generated assertions after expr behavior changes; copy-pasted filter expressions into assert files.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- AverageInterval expects a slice of times
- groupby wrong type
- unexpected type %t (%v) while running '%s'
- invalid type for ip : %T
- element at index %d is not a time.Time
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/3cc0166e1094c940.
Report an issue: GitHub.