{"record":{"id":"33418293b44a1f31","repo":"crowdsecurity/crowdsec","slug":"while-creating-allowlist-s-s","errorCode":null,"errorMessage":"while creating allowlist %s: %s","messagePattern":"while creating allowlist (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiserver/apic.go","lineNumber":769,"sourceCode":"\n\t\tif err := json.Unmarshal([]byte(item), j); err != nil {\n\t\t\treturn fmt.Errorf(\"while unmarshalling allowlist item: %s\", err)\n\t\t}\n\n\t\titems = append(items, j)\n\t}\n\n\tlist, err := a.dbClient.GetAllowListByID(ctx, *link.ID, false)\n\tif err != nil {\n\t\tif !ent.IsNotFound(err) {\n\t\t\treturn fmt.Errorf(\"while getting allowlist %s: %s\", *link.Name, err)\n\t\t}\n\t}\n\n\tif list == nil {\n\t\tlist, err = a.dbClient.CreateAllowList(ctx, *link.Name, description, *link.ID, true)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"while creating allowlist %s: %s\", *link.Name, err)\n\t\t}\n\t}\n\n\tadded, err := a.dbClient.ReplaceAllowlist(ctx, list, items, true)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while replacing allowlist %s: %s\", *link.Name, err)\n\t}\n\n\tlog.Infof(\"added %d values to allowlist %s\", added, list.Name)\n\n\tif list.Name != *link.Name || list.Description != description {\n\t\terr = a.dbClient.UpdateAllowlistMeta(ctx, *link.ID, *link.Name, description)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"while updating allowlist meta %s: %s\", *link.Name, err)\n\t\t}\n\t}\n\n\tlog.Infof(\"Allowlist %s updated\", *link.Name)","sourceCodeStart":751,"sourceCodeEnd":787,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/apic.go#L751-L787","documentation":"When GetAllowListByID returns NotFound (list == nil), updateOneAllowlist creates the allowlist locally via CreateAllowList(name, description, ID, fromConsole=true). This error wraps a failure of that INSERT, meaning the local allowlist record could not be created with the console-provided ID.","triggerScenarios":"CreateAllowList fails on first sync of a console-managed allowlist: DB write error, UNIQUE constraint conflict (an allowlist with the same name or ID already exists but the earlier lookup didn't find it), or DB connection loss.","commonSituations":"Stale local allowlist row with the same name created before console enrollment; SQLite lock or full disk during enrollment; duplicated allowlist entries in console config; DB in read-only mode.","solutions":["Check cscli allowlists list for an existing allowlist with the same name or ID and remove/rename it","Inspect the wrapped %s message for a UNIQUE/duplicate-key constraint vs connection error","Verify DB is writable and not locked (disk space, sqlite lock, other processes)","If the stale entry was console-created, delete it and let the sync recreate it","Restart crowdsec to reset the DB connection and re-trigger the sync"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check for an existing allowlist with the same name before first sync\nexisting := cscli_allowlists_list() // e.g. cscli allowlists list -o json\nfor _, al := range existing {\n    if al.Name == linkName || al.ID == linkID {\n        log.Warnf(\"allowlist %s (%s) already exists locally\", al.Name, al.ID)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := a.updateOneAllowlist(ctx, client, link); err != nil {\n    if strings.Contains(err.Error(), \"while creating allowlist\") {\n        log.Errorf(\"could not create allowlist %s locally (duplicate name/ID or DB error): %s\", *link.Name, err)\n    } else {\n        log.Errorf(\"updating allowlists from CAPI: %s\", err)\n    }\n}","preventionTips":["Avoid manually creating allowlists with the same name as console-managed ones","Check cscli allowlists list after enrollment to catch duplicates early","Keep the DB writable and unlocked during enrollment","Don't run crowdsec against a read-only or shared SQLite file"],"tags":["database","allowlist","create","sqlite"],"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"}