{"record":{"id":"a8f195595d899367","repo":"crowdsecurity/crowdsec","slug":"allowlist-s-not-found","errorCode":null,"errorMessage":"allowlist %s not found","messagePattern":"allowlist (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/allowlists.go","lineNumber":59,"sourceCode":"\nfunc (c *Client) DeleteAllowList(ctx context.Context, name string, fromConsole bool) error {\n\tnbDeleted, err := c.Ent.AllowListItem.Delete().Where(allowlistitem.HasAllowlistWith(allowlist.NameEQ(name), allowlist.FromConsoleEQ(fromConsole))).Exec(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to delete allowlist items: %w\", err)\n\t}\n\n\tc.Log.Debugf(\"deleted %d items from allowlist %s\", nbDeleted, name)\n\n\tnbDeleted, err = c.Ent.AllowList.\n\t\tDelete().\n\t\tWhere(allowlist.NameEQ(name), allowlist.FromConsoleEQ(fromConsole)).\n\t\tExec(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to delete allowlist: %w\", err)\n\t}\n\n\tif nbDeleted == 0 {\n\t\treturn fmt.Errorf(\"allowlist %s not found\", name)\n\t}\n\n\treturn nil\n}\n\nfunc (c *Client) DeleteAllowListByID(ctx context.Context, name string, allowlistID string, fromConsole bool) error {\n\tnbDeleted, err := c.Ent.AllowListItem.Delete().Where(allowlistitem.HasAllowlistWith(allowlist.AllowlistIDEQ(allowlistID), allowlist.FromConsoleEQ(fromConsole))).Exec(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to delete allowlist items: %w\", err)\n\t}\n\n\tc.Log.Debugf(\"deleted %d items from allowlist %s\", nbDeleted, name)\n\n\tnbDeleted, err = c.Ent.AllowList.\n\t\tDelete().\n\t\tWhere(allowlist.AllowlistIDEQ(allowlistID), allowlist.FromConsoleEQ(fromConsole)).\n\t\tExec(ctx)\n\tif err != nil {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/allowlists.go#L41-L77","documentation":"DeleteAllowList deletes an allowlist's items then the allowlist row itself, matched by name and from_console flag. After the delete Exec, if zero rows were removed it means no allowlist with that exact name (and console origin) existed, so the function reports 'allowlist %s not found'. Note the items delete already ran, so this error fires after a successful (empty) delete.","triggerScenarios":"Calling Client.DeleteAllowList(ctx, name, fromConsole) with a name that does not exist in the allowlists table, or an existing allowlist whose FromConsole flag does not match the fromConsole argument (the WHERE clause includes FromConsoleEQ).","commonSituations":"Typo in 'cscli allowlists delete <name>'; deleting a console-managed allowlist locally without passing the right origin; allowlist already deleted in a prior run or on another node sharing the same database; name vs allowlist_id confusion (delete by name when only an ID is known).","solutions":["List existing allowlists (cscli allowlists list or Client.ListAllowLists) and use the exact name shown","Match the fromConsole flag: use the console-subcommand variant for console-managed allowlists, the local one for local ones","If deleting by ID, call DeleteAllowListByID instead of DeleteAllowList","Treat the error as idempotent: ignore 'not found' if your goal is just to ensure the allowlist is gone"],"exampleFix":"// before\ncscli allowlists delete my-allwlist\n// after\ncscli allowlists list   # confirm exact name\ncscli allowlists delete my-allowlist","handlingStrategy":"validation","validationCode":"lists, err := client.ListAllowLists(ctx, false)\nif err != nil { return err }\nfound := false\nfor _, l := range lists {\n    if l.Name == name && l.FromConsole == fromConsole { found = true; break }\n}\nif !found { return fmt.Errorf(\"allowlist %q does not exist; nothing to delete\", name) }","typeGuard":null,"tryCatchPattern":"if err := client.DeleteAllowList(ctx, name, fromConsole); err != nil {\n    if strings.Contains(err.Error(), \"not found\") { /* already gone: treat as success */ } else { return err }\n}","preventionTips":["Always fetch the allowlist (GetAllowList) before deleting to confirm name and origin","Match the fromConsole flag to how the allowlist was created","Write deletion scripts to be idempotent about 'not found'"],"tags":["database","allowlist","not-found"],"backgroundTag":"entity-not-found","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"}