{"record":{"id":"69071985d85b3bac","repo":"crowdsecurity/crowdsec","slug":"while-looking-for-capi-alert-w","errorCode":null,"errorMessage":"while looking for CAPI alert: %w","messagePattern":"while looking for CAPI alert: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiserver/apic.go","lineNumber":438,"sourceCode":"\t\tend := min(start+batchSize, len(cache))\n\n\t\tif err := a.sendBatch(ctx, cache[start:end]); err != nil {\n\t\t\tlog.Errorf(\"sending signal to central API: %s\", err)\n\t\t\treturn\n\t\t}\n\t}\n}\n\nfunc (a *apic) CAPIPullIsOld(ctx context.Context) (bool, error) {\n\t/*only pull community blocklist if it's older than 1h30 */\n\talerts := a.dbClient.Ent.Alert.Query()\n\n\talerts = alerts.Where(alert.HasDecisionsWith(decision.OriginEQ(database.CapiMachineID)))\n\talerts = alerts.Where(alert.CreatedAtGTE(time.Now().UTC().Add(-time.Duration(1*time.Hour + 30*time.Minute)))) //nolint:unconvert\n\n\tcount, err := alerts.Count(ctx)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"while looking for CAPI alert: %w\", err)\n\t}\n\n\tif count > 0 {\n\t\tlog.Info(\"last CAPI pull is newer than 1h30, skip.\")\n\t\treturn false, nil\n\t}\n\n\treturn true, nil\n}\n\nfunc (a *apic) HandleDeletedDecisionsV3(ctx context.Context, deletedDecisions []*modelscapi.GetDecisionsStreamResponseDeletedItem, deleteCounters map[string]map[string]int) (int, error) {\n\tvar nbDeleted int\n\n\tfor _, decisions := range deletedDecisions {\n\t\tscope := decisions.Scope\n\n\t\tfor _, decision := range decisions.Decisions {\n\t\t\tfilter := map[string][]string{","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/apic.go#L420-L456","documentation":"The database query counting CAPI-originated alerts created in the last 1h30m failed while determining whether the community blocklist pull is stale (CAPIPullIsOld). This is a DB-level failure (connection, schema, ent query error), not a blocklist problem; the freshness check cannot run so the caller cannot decide whether a pull is due.","triggerScenarios":"Thrown at pkg/apiserver/apic.go:438 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check database connectivity and credentials for the LAPI database","Inspect the wrapped error for the SQL/ent failure — it may reveal schema drift requiring a migration check","Verify the alert and decision tables exist and migrations completed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}