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

  1. Check logs for the 'QueryDecisionCountByScenario :' warning to see the real error
  2. Re-run migrations / restart crowdsec to ensure the decisions table schema is complete
  3. If migrations fail, back up and inspect the decisions table for leftover foreign keys/columns
  4. 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

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


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