{"record":{"id":"5d34d756e9bcf9b1","repo":"crowdsecurity/crowdsec","slug":"duration-is-required","errorCode":null,"errorMessage":"duration is required","messagePattern":"duration is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/leakybucket/buckettype.go","lineNumber":65,"sourceCode":"\t\treturn fmt.Errorf(\"invalid capacity '%d': must be 0\", f.Spec.Capacity)\n\t}\n\n\treturn nil\n}\n\nfunc (TriggerType) BuildProcessors(_ *BucketFactory) []Processor {\n\treturn []Processor{&TriggerProcessor{}}\n}\n\ntype CounterType struct{}\n\nfunc (CounterType) Validate(f *BucketFactory) error {\n\tif f.Spec.Capacity != -1 {\n\t\treturn fmt.Errorf(\"invalid capacity '%d': must be -1\", f.Spec.Capacity)\n\t}\n\n\tif f.Spec.Duration == \"\" {\n\t\treturn errors.New(\"duration is required\")\n\t}\n\n\tif f.duration <= 0 {\n\t\treturn fmt.Errorf(\"invalid duration '%d': must be > 0\", f.duration)\n\t}\n\n\treturn nil\n}\n\nfunc (CounterType) BuildProcessors(_ *BucketFactory) []Processor {\n\treturn []Processor{&DumbProcessor{}}\n}\n\ntype ConditionalType struct{}\n\nfunc (ConditionalType) Validate(f *BucketFactory) error {\n\tif f.Spec.Capacity != -1 {\n\t\tf.logger.Warnf(\"Using a value different than -1 as capacity for conditional bucket, this may lead to unexpected overflows\")","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/leakybucket/buckettype.go#L47-L83","documentation":"CounterType.Validate enforces that a counter bucket has capacity exactly -1 and a non-empty `duration` string. This error is thrown when the counter bucket spec has no duration, meaning the counter would never expire, so validation refuses to build it.","triggerScenarios":"Loading a bucket with type: counter whose spec lacks the `duration:` field (f.Spec.Duration == \"\"), during bucket factory validation.","commonSituations":"Writing a counter bucket from scratch and forgetting duration; converting a leaky bucket (which uses leakspeed) into a counter without swapping the field; copy-pasted bucket blocks with duration removed.","solutions":["Add a valid duration to the counter spec, e.g. `duration: 1m`","Ensure `capacity: -1` is set as well — Validate rejects any other capacity first","Check YAML indentation so `duration` sits inside the bucket spec block","Reload the scenario and confirm the error is gone"],"exampleFix":"// before\n# type: counter\n# capacity: -1\n// after\n# type: counter\n# capacity: -1\n# duration: 1m","handlingStrategy":"validation","validationCode":"// before loading the bucket config\nif b.Spec.Type == \"counter\" {\n    if b.Spec.Capacity != -1 { return fmt.Errorf(\"counter capacity must be -1\") }\n    if b.Spec.Duration == \"\" { return fmt.Errorf(\"duration is required\") }\n    if _, err := time.ParseDuration(b.Spec.Duration); err != nil { return err }\n}","typeGuard":null,"tryCatchPattern":"if err := CounterType{}.Validate(factory); err != nil {\n    if strings.Contains(err.Error(), \"duration is required\") {\n        return fmt.Errorf(\"counter bucket %q: add a duration like '1m'\", factory.Name)\n    }\n    return err\n}","preventionTips":["Remember counter buckets use duration, not leakspeed, when converting from leaky","Keep capacity: -1 on counter buckets or validation fails earlier","Lint scenario YAML against the bucket schema before submission","Test custom scenarios with cscli hubtest before deploying"],"tags":["leakybucket","yaml-config","validation","crowdsec"],"backgroundTag":"missing-required-config-field","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"}