{"record":{"id":"39554baa9c2cfc83","repo":"crowdsecurity/crowdsec","slug":"unable-to-create-bouncer-w","errorCode":null,"errorMessage":"unable to create bouncer: %w","messagePattern":"unable to create bouncer: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/bouncers.go","lineNumber":96,"sourceCode":"\treturn result, nil\n}\n\nfunc (c *Client) CreateBouncer(ctx context.Context, name string, ipAddr string, apiKey string, authType string, autoCreated bool) (*ent.Bouncer, error) {\n\tbouncer, err := c.Ent.Bouncer.\n\t\tCreate().\n\t\tSetName(name).\n\t\tSetAPIKey(apiKey).\n\t\tSetRevoked(false).\n\t\tSetAuthType(authType).\n\t\tSetIPAddress(ipAddr).\n\t\tSetAutoCreated(autoCreated).\n\t\tSave(ctx)\n\tif err != nil {\n\t\tif ent.IsConstraintError(err) {\n\t\t\treturn nil, fmt.Errorf(\"bouncer %s already exists\", name)\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"unable to create bouncer: %w\", err)\n\t}\n\n\treturn bouncer, nil\n}\n\nfunc (c *Client) DeleteBouncer(ctx context.Context, name string) error {\n\tnbDeleted, err := c.Ent.Bouncer.\n\t\tDelete().\n\t\tWhere(bouncer.NameEQ(name)).\n\t\tExec(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif nbDeleted == 0 {\n\t\treturn &BouncerNotFoundError{BouncerName: name}\n\t}\n","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/bouncers.go#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"DB file permissions changed (crowdsec cannot write), disk full, or binary newer than the schema so the insert references missing columns.","solutions":["Read the wrapped error to identify the root cause (lock, permissions, missing table)","Check DB file ownership/permissions so the crowdsec user can write","Free disk space if the filesystem is full","Run the DB migration if the schema is older than the binary"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if err := canWriteDB(dbPath); err != nil {\n    return fmt.Errorf(\"database not writable, cannot create bouncer: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"b, err := c.CreateBouncer(ctx, name, ip, key, authType, auto)\nif err != nil {\n    var constraint *ent.ConstraintError\n    if errors.As(err, &constraint) { /* handled as already-exists */ }\n    // otherwise: inspect wrapped cause - lock, permissions, schema - before retrying\n    return fmt.Errorf(\"bouncer creation failed: %w\", err)\n}","preventionTips":["Verify the DB file is writable by the crowdsec user and the disk is not full","Keep the binary and DB schema versions in sync (run migrations on upgrade)","Raise SQLite busy_timeout when bouncers register during heavy daemon write load"],"tags":["database","bouncer","insert","ent"],"backgroundTag":"database-write-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}