crowdsecurity/crowdsec · error · QueryFail

listing bouncers: %w: %w

Error message

listing bouncers: %w: %w

What it means

ListBouncers runs a plain ent query for all bouncers. On failure it wraps the error together with the shared QueryFail sentinel, producing the double-%w format 'listing bouncers: <err>: <QueryFail text>'. It means the bouncer table could not be read.

Source

Thrown at pkg/database/bouncers.go:75

		return nil, err
	}

	return result, nil
}

func (c *Client) SelectBouncerByName(ctx context.Context, bouncerName string) (*ent.Bouncer, error) {
	result, err := c.Ent.Bouncer.Query().Where(bouncer.NameEQ(bouncerName)).First(ctx)
	if err != nil {
		return nil, err
	}

	return result, nil
}

func (c *Client) ListBouncers(ctx context.Context) ([]*ent.Bouncer, error) {
	result, err := c.Ent.Bouncer.Query().All(ctx)
	if err != nil {
		return nil, fmt.Errorf("listing bouncers: %w: %w", err, QueryFail)
	}

	return result, nil
}

func (c *Client) CreateBouncer(ctx context.Context, name string, ipAddr string, apiKey string, authType string, autoCreated bool) (*ent.Bouncer, error) {
	bouncer, err := c.Ent.Bouncer.
		Create().
		SetName(name).
		SetAPIKey(apiKey).
		SetRevoked(false).
		SetAuthType(authType).
		SetIPAddress(ipAddr).
		SetAutoCreated(autoCreated).
		Save(ctx)
	if err != nil {
		if ent.IsConstraintError(err) {
			return nil, fmt.Errorf("bouncer %s already exists", name)

View on GitHub (pinned to 909b515798)

Solutions

  1. Confirm cscli and the daemon point to the same DB (check db_config in crowdsec.yaml)
  2. Read the wrapped error; 'no such table: bouncers' means run the DB migration/upgrade flow
  3. Resolve SQLite lock contention or restore a corrupted DB from backup
Defensive patterns

Strategy: try-catch

Try / catch

bouncers, err := c.ListBouncers(ctx)
if err != nil {
    if errors.Is(err, QueryFail) || strings.Contains(err.Error(), "locked") {
        return retryAfterBackoff(ctx, func() error { b, e := c.ListBouncers(ctx); bouncers = b; return e })
    }
    return fmt.Errorf("cannot list bouncers, check DB availability: %w", err)
}

Prevention

When it happens

Trigger: Any of validBouncerID, cscli 'bouncers list' (delete/List), pushUsageMetrics, or GetMetrics when the ent Bouncer.Query().All fails: SQLite locked, file missing/corrupt, schema version mismatch.

Common situations: Running 'cscli bouncers list' while the daemon bulk-inserts metrics; pointing cscli at a different/absent DB file than the daemon uses.

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