crowdsecurity/crowdsec · error

unable to create bouncer: %w

Error message

unable to create bouncer: %w

What it means

CreateBouncer's non-constraint error path: the ent Save failed for any reason other than a uniqueness constraint (DB locked, IO error, connection failure for a client-server DB). The bouncer was not created and no key was issued.

Source

Thrown at pkg/database/bouncers.go:96

	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)
		}

		return nil, fmt.Errorf("unable to create bouncer: %w", err)
	}

	return bouncer, nil
}

func (c *Client) DeleteBouncer(ctx context.Context, name string) error {
	nbDeleted, err := c.Ent.Bouncer.
		Delete().
		Where(bouncer.NameEQ(name)).
		Exec(ctx)
	if err != nil {
		return err
	}

	if nbDeleted == 0 {
		return &BouncerNotFoundError{BouncerName: name}
	}

View on GitHub (pinned to 909b515798)

Solutions

  1. Read the wrapped error to identify the root cause (lock, permissions, missing table)
  2. Check DB file ownership/permissions so the crowdsec user can write
  3. Free disk space if the filesystem is full
  4. Run the DB migration if the schema is older than the binary
Defensive patterns

Strategy: try-catch

Validate before calling

if err := canWriteDB(dbPath); err != nil {
    return fmt.Errorf("database not writable, cannot create bouncer: %w", err)
}

Try / catch

b, err := c.CreateBouncer(ctx, name, ip, key, authType, auto)
if err != nil {
    var constraint *ent.ConstraintError
    if errors.As(err, &constraint) { /* handled as already-exists */ }
    // otherwise: inspect wrapped cause - lock, permissions, schema - before retrying
    return fmt.Errorf("bouncer creation failed: %w", err)
}

Prevention

When it happens

Trigger: Calling CreateBouncer ('cscli bouncers add', bouncer auto-registration via authTLS/authPlain) when the insert fails without being a constraint error - SQLite lock/IO errors, read-only DB file, schema mismatch.

Common situations: DB file permissions changed (crowdsec cannot write), disk full, or binary newer than the schema so the insert references missing columns.

Related errors


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