crowdsecurity/crowdsec · error

fail to get decision: %w

Error message

fail to get decision: %w

What it means

GetActiveDecisionsTimeLeftByValue failed while fetching the most recent active decision (decisions.First(ctx), ordered by until descending). Any database error other than ent.IsNotFound (which is treated as 'no decision') is wrapped with this message.

Source

Thrown at pkg/database/decisions.go:432

	if err != nil {
		return 0, fmt.Errorf("unable to convert '%s' to int: %w", decisionValue, err)
	}

	contains := true
	decisions := c.Ent.Decision.Query().Where(
		decision.UntilGT(time.Now().UTC()),
	)

	decisions, err = decisionIPFilter(decisions, contains, rng)
	if err != nil {
		return 0, fmt.Errorf("fail to apply StartIpEndIpFilter: %w", err)
	}

	decisions = decisions.Order(ent.Desc(decision.FieldUntil))

	decision, err := decisions.First(ctx)
	if err != nil && !ent.IsNotFound(err) {
		return 0, fmt.Errorf("fail to get decision: %w", err)
	}

	if decision == nil {
		return 0, nil
	}

	return decision.Until.Sub(time.Now().UTC()), nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Inspect the wrapped driver error in crowdsec logs to find the root cause.
  2. Verify DB connectivity and that the decisions table exists (`cscli decisions list` exercises the same table).
  3. Restart crowdsec / reconnect the database and retry.

Example fix

// before
tl, err := client.GetActiveDecisionsTimeLeftByValue(ctx, value)
// after: treat as no decision only on NotFound, everything else is a real error
tl, err := client.GetActiveDecisionsTimeLeftByValue(ctx, value)
if err != nil {
	log.Warnf("time-left lookup failed for %s: %v", value, err)
}
Defensive patterns

Strategy: try-catch

Try / catch

tl, err := client.GetActiveDecisionsTimeLeftByValue(ctx, value)
if err != nil {
	// Only ent.IsNotFound means 'no decision'; anything else is a DB failure.
	log.Warnf("time-left lookup failed: %v", err)
	return 0, nil // or retry
}

Prevention

When it happens

Trigger: Calling GetActiveDecisionsTimeLeftByValue when the ent First(ctx) query fails for a reason other than no rows: DB connection lost, driver error, table missing, or query failure.

Common situations: Database restarted mid-request; SQLite locked by another process; credentials rotated; schema dropped after a failed migration.

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/b7f8ac26659955b6. Report an issue: GitHub.