{"record":{"id":"8b1f270528265fc1","repo":"crowdsecurity/crowdsec","slug":"get-all-decisions-with-filters-w","errorCode":null,"errorMessage":"get all decisions with filters: %w","messagePattern":"get all decisions with filters: %w","errorType":"exception","errorClass":"QueryFail","httpStatus":null,"severity":"error","filePath":"pkg/database/decisions.go","lineNumber":43,"sourceCode":"}\n\nfunc (c *Client) QueryAllDecisionsWithFilters(ctx context.Context, now time.Time, filter map[string][]string) ([]*ent.Decision, error) {\n\t// Do not select all fields.\n\t// This can get pretty expensive network-wise if there are a lot of decisions and you are using a remote database\n\tquery := c.Ent.Decision.Query().\n\t\tSelect(decision.FieldID, decision.FieldUntil, decision.FieldScenario, decision.FieldScope, decision.FieldValue, decision.FieldType, decision.FieldOrigin, decision.FieldUUID).\n\t\tWhere(\n\t\t\tdecision.UntilGT(now),\n\t\t)\n\t// Allow a bouncer to ask for non-deduplicated results\n\tif v, ok := filter[\"dedup\"]; !ok || v[0] != \"false\" {\n\t\tquery = query.Where(longestDecisionForScopeTypeValue)\n\t}\n\n\tquery, err := applyDecisionFilter(query, filter)\n\tif err != nil {\n\t\tc.Log.Warningf(\"QueryAllDecisionsWithFilters : %s\", err)\n\t\treturn []*ent.Decision{}, fmt.Errorf(\"get all decisions with filters: %w\", QueryFail)\n\t}\n\n\tquery = query.Order(ent.Asc(decision.FieldID))\n\n\tdata, err := query.All(ctx)\n\tif err != nil {\n\t\tc.Log.Warningf(\"QueryAllDecisionsWithFilters : %s\", err)\n\t\treturn []*ent.Decision{}, fmt.Errorf(\"get all decisions with filters: %w\", QueryFail)\n\t}\n\n\treturn data, nil\n}\n\nfunc (c *Client) LatestDecisionID(ctx context.Context) (int, error) {\n\tlatest, err := c.Ent.Decision.Query().\n\t\tSelect(decision.FieldID).\n\t\tOrder(ent.Desc(decision.FieldID)).\n\t\tFirst(ctx)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/decisions.go#L25-L61","documentation":"This error is returned by Client.QueryAllDecisionsWithFilters when the decision filter expression cannot be translated/applied to the ent query. It wraps the shared sentinel QueryFail (\"unable to query\"), so the underlying cause is only available in the CrowdSec log line ('QueryAllDecisionsWithFilters : <err>') emitted just before the error is returned.","triggerScenarios":"applyDecisionFilter fails while parsing a filter map key/value into an ent predicate — e.g. a caller (LAPI /decisions request) passes an unsupported filter key, a malformed value (bad scope, non-boolean 'has been remediated', invalid IP in 'ip' range), or the contains-ip helper cannot parse the value.","commonSituations":"A bouncer or cscli calls the LAPI with ?scope=...&value=...&type=... where one value doesn't match expected formats (e.g. scope 'ip' with a non-IP/CIDR value, or an unknown filter parameter added by a newer client against an older LAPI).","solutions":["Check the crowdsec/LAPI log for the 'QueryAllDecisionsWithFilters :' warning to see the real underlying parse error","Validate filter keys and value formats (scope, type, value, ip) before sending the request","Remove unknown/unsupported query parameters from the /decisions call","Test the filter locally with `cscli decisions list --contains ...` to reproduce the parse failure"],"exampleFix":"// before\ndecisions, err := client.Decisions.List(ctx, map[string][]string{\"scopes\": {\"ip\"}})\n// after (use valid filter keys/values)\ndecisions, err := client.Decisions.List(ctx, map[string][]string{\"scope\": {\"ip\"}, \"value\": {\"1.2.3.4\"}})","handlingStrategy":"validation","validationCode":"validKeys := map[string]bool{\"scope\":true,\"value\":true,\"type\":true,\"origin\":true,\"scenario\":true,\"ip\":true,\"since\":true,\"hasBeenRemediated\":true,\"hasActiveDecision\":true}\nfor k, vs := range filter {\n    if !validKeys[k] { return fmt.Errorf(\"unsupported decision filter key %q\", k) }\n    for _, v := range vs { if v == \"\" { return fmt.Errorf(\"empty value for filter %q\", k) } }\n}","typeGuard":null,"tryCatchPattern":"decisions, err := client.QueryAllDecisionsWithFilters(ctx, filter)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to query\") {\n        // malformed filter; check LAPI logs for 'QueryAllDecisionsWithFilters :'\n        return fmt.Errorf(\"bad decision filter: %w\", err)\n    }\n    return err\n}","preventionTips":["Only send documented filter keys to /decisions","Validate scope/value/type formats client-side (IP parse for scope=ip)","URL-encode HTTP query parameters","Check LAPI logs first — the wrapped sentinel hides the real cause"],"tags":["database","crowdsec","lapi","filter-parsing"],"backgroundTag":"database-query-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"}