{"record":{"id":"b7f8ac26659955b6","repo":"crowdsecurity/crowdsec","slug":"fail-to-get-decision-w","errorCode":null,"errorMessage":"fail to get decision: %w","messagePattern":"fail to get decision: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/decisions.go","lineNumber":432,"sourceCode":"\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"unable to convert '%s' to int: %w\", decisionValue, err)\n\t}\n\n\tcontains := true\n\tdecisions := c.Ent.Decision.Query().Where(\n\t\tdecision.UntilGT(time.Now().UTC()),\n\t)\n\n\tdecisions, err = decisionIPFilter(decisions, contains, rng)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"fail to apply StartIpEndIpFilter: %w\", err)\n\t}\n\n\tdecisions = decisions.Order(ent.Desc(decision.FieldUntil))\n\n\tdecision, err := decisions.First(ctx)\n\tif err != nil && !ent.IsNotFound(err) {\n\t\treturn 0, fmt.Errorf(\"fail to get decision: %w\", err)\n\t}\n\n\tif decision == nil {\n\t\treturn 0, nil\n\t}\n\n\treturn decision.Until.Sub(time.Now().UTC()), nil\n}\n","sourceCodeStart":414,"sourceCodeEnd":441,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/decisions.go#L414-L441","documentation":"GetActiveDecisionsTimeLeftByValue failed while fetching the most recent active decision (decisions.First(ctx), ordered by until descending). Any database error other than ent.IsNotFound (which is treated as 'no decision') is wrapped with this message.","triggerScenarios":"Calling GetActiveDecisionsTimeLeftByValue when the ent First(ctx) query fails for a reason other than no rows: DB connection lost, driver error, table missing, or query failure.","commonSituations":"Database restarted mid-request; SQLite locked by another process; credentials rotated; schema dropped after a failed migration.","solutions":["Inspect the wrapped driver error in crowdsec logs to find the root cause.","Verify DB connectivity and that the decisions table exists (`cscli decisions list` exercises the same table).","Restart crowdsec / reconnect the database and retry."],"exampleFix":"// before\ntl, err := client.GetActiveDecisionsTimeLeftByValue(ctx, value)\n// after: treat as no decision only on NotFound, everything else is a real error\ntl, err := client.GetActiveDecisionsTimeLeftByValue(ctx, value)\nif err != nil {\n\tlog.Warnf(\"time-left lookup failed for %s: %v\", value, err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"tl, err := client.GetActiveDecisionsTimeLeftByValue(ctx, value)\nif err != nil {\n\t// Only ent.IsNotFound means 'no decision'; anything else is a DB failure.\n\tlog.Warnf(\"time-left lookup failed: %v\", err)\n\treturn 0, nil // or retry\n}","preventionTips":["Use connection pooling/health checks on MySQL/Postgres backends.","Monitor SQLite lock contention in multi-process setups.","Verify decisions table integrity after crashes (`cscli decisions list`)."],"tags":["database","ent","crowdsec","query-failed"],"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"}