crowdsecurity/crowdsec · error · QueryFail
count all decisions with filters: %w
Error message
count all decisions with filters: %w
What it means
Returned by QueryDecisionCountByScenario when applyDecisionFilter fails on the (effectively empty) filter map. Wraps QueryFail ("unable to query"); the underlying error is logged as 'QueryDecisionCountByScenario : <err>'.
Source
Thrown at pkg/database/decisions.go:111
data, err := query.All(ctx)
if err != nil {
c.Log.Warningf("QueryExpiredDecisionsWithFilters : %s", err)
return []*ent.Decision{}, fmt.Errorf("expired decisions: %w", QueryFail)
}
return data, nil
}
func (c *Client) QueryDecisionCountByScenario(ctx context.Context) ([]*DecisionsByScenario, error) {
query := c.Ent.Decision.Query().Where(
decision.UntilGT(time.Now().UTC()),
)
query, err := applyDecisionFilter(query, make(map[string][]string))
if err != nil {
c.Log.Warningf("QueryDecisionCountByScenario : %s", err)
return nil, fmt.Errorf("count all decisions with filters: %w", QueryFail)
}
var r []*DecisionsByScenario
err = query.GroupBy(decision.FieldScenario, decision.FieldOrigin, decision.FieldType).Aggregate(ent.Count()).Scan(ctx, &r)
if err != nil {
c.Log.Warningf("QueryDecisionCountByScenario : %s", err)
return nil, fmt.Errorf("count all decisions with filters: %w", QueryFail)
}
return r, nil
}
func (c *Client) QueryDecisionWithFilter(ctx context.Context, filter map[string][]string) ([]*ent.Decision, error) {
var (
err error
data []*ent.Decision
)View on GitHub (pinned to 909b515798)
Solutions
- Check logs for the 'QueryDecisionCountByScenario :' warning to see the real error
- Re-run migrations / restart crowdsec to ensure the decisions table schema is complete
- If migrations fail, back up and inspect the decisions table for leftover foreign keys/columns
- Report as a bug with the log line if it reproduces with an empty filter
Example fix
// before # ignore and keep querying with broken schema cscli metrics // after systemctl stop crowdsec && cp crowdsec.db crowdsec.db.bak cscli db migrate && systemctl start crowdsec
Defensive patterns
Strategy: try-catch
Try / catch
counts, err := client.QueryDecisionCountByScenario(ctx)
if err != nil {
log.Warnf("decision counts unavailable: %v", err)
counts = []*database.DecisionsByScenario{} // degrade metrics, don't crash
} Prevention
- Don't manually alter the decisions table schema
- Verify schema integrity after restores from backup
- Report reproducible failures with the underlying log line to CrowdSec
When it happens
Trigger: Rare: the built-in empty filter map cannot be translated, typically indicating an internal invariant problem or a corrupted/absent ent schema at runtime rather than caller input.
Common situations: Seen during dashboard/metrics aggregation (cscli metrics / console enrollment) when the DB layer is in a broken state — e.g. partially applied migration leaving the decisions table invalid.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- unable to query alerts for uuid %s: %w
- expired decisions: %w
- no database configuration provided
- unable to update
- unable to delete
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/fc59b240682c2786.
Report an issue: GitHub.