{"record":{"id":"915863d0aaaec6b0","repo":"crowdsecurity/crowdsec","slug":"invalid-prior-must-be-0-and-1","errorCode":null,"errorMessage":"invalid prior: must be > 0 and <= 1","messagePattern":"invalid prior: must be > 0 and <= 1","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/leakybucket/buckettype.go","lineNumber":113,"sourceCode":"\t\treturn fmt.Errorf(\"invalid leakspeed '%s': must be > 0\", f.Spec.LeakSpeed)\n\t}\n\n\treturn nil\n}\n\nfunc (ConditionalType) BuildProcessors(_ *BucketFactory) []Processor {\n\treturn []Processor{&DumbProcessor{}}\n}\n\ntype BayesianType struct{}\n\nfunc (BayesianType) Validate(f *BucketFactory) error {\n\tif len(f.Spec.BayesianConditions) == 0 {\n\t\treturn errors.New(\"bayesian conditions are required\")\n\t}\n\n\tif f.Spec.BayesianPrior <= 0 || f.Spec.BayesianPrior > 1 {\n\t\treturn errors.New(\"invalid prior: must be > 0 and <= 1\")\n\t}\n\n\tif f.Spec.BayesianThreshold == 0 || f.Spec.BayesianThreshold > 1 {\n\t\treturn errors.New(\"invalid threshold: must be > 0 and <= 1\")\n\t}\n\n\tif f.Spec.Capacity != -1 {\n\t\treturn errors.New(\"capacity must be -1\")\n\t}\n\n\treturn nil\n}\n\nfunc (BayesianType) BuildProcessors(_ *BucketFactory) []Processor {\n\treturn []Processor{&DumbProcessor{}}\n}\n","sourceCodeStart":95,"sourceCodeEnd":130,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/leakybucket/buckettype.go#L95-L130","documentation":"BayesianType.Validate checks that bayesian_prior is strictly greater than 0 and at most 1, since a prior is a probability. This error means the configured prior falls outside (0, 1] — zero, negative, or greater than 1 — so the Bayesian math would be meaningless and the bucket is rejected.","triggerScenarios":"Loading a type: bayesian bucket whose `bayesian_prior:` is 0, negative, or > 1 (e.g. written as a percentage like 50 instead of 0.5).","commonSituations":"Specifying the prior as a percentage (0-100) instead of a fraction; leaving bayesian_prior at 0 because it was unset and defaulted; typo such as 1.5 or -0.2 in the scenario YAML.","solutions":["Set bayesian_prior to a value in (0, 1], e.g. 0.5 — convert percentages by dividing by 100","Check that the value isn't 0 due to a defaulted/unset field","Confirm it's a plain number in YAML, not quoted or expressed with a unit","Also fix bayesian_threshold if it's 0 or > 1 (the next validation check)","Reload the scenario and verify the bucket loads"],"exampleFix":"// before\n# bayesian_prior: 50\n// after\n# bayesian_prior: 0.5","handlingStrategy":"validation","validationCode":"// before loading the bucket config\nif b.Spec.Type == \"bayesian\" {\n    if b.Spec.BayesianPrior <= 0 || b.Spec.BayesianPrior > 1 {\n        return fmt.Errorf(\"bayesian_prior must be in (0, 1], got %v\", b.Spec.BayesianPrior)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := BayesianType{}.Validate(factory); err != nil {\n    if strings.Contains(err.Error(), \"invalid prior\") {\n        return fmt.Errorf(\"bayesian bucket %q: bayesian_prior is a probability in (0, 1], e.g. 0.5\", factory.Name)\n    }\n    return err\n}","preventionTips":["Express the prior as a fraction (0.5), never a percentage (50)","Don't leave bayesian_prior at 0 expecting a default — 0 is rejected","Validate both prior and threshold are in (0, 1] together","Test bayesian scenarios with cscli hubtest before deploying"],"tags":["leakybucket","bayesian","yaml-config","validation"],"backgroundTag":"invalid-argument-value","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"}