{"record":{"id":"97a497b5e4b387f6","repo":"crowdsecurity/crowdsec","slug":"while-validating-reader-configuration-w","errorCode":null,"errorMessage":"while validating reader configuration: %w","messagePattern":"while validating reader configuration: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/kafka/config.go","lineNumber":208,"sourceCode":"\n\tif c.BatchConfiguration.BatchMaxBytes != 0 {\n\t\trConf.MaxBytes = c.BatchConfiguration.BatchMaxBytes\n\t}\n\n\tif c.BatchConfiguration.BatchMaxWait != 0 {\n\t\trConf.MaxWait = c.BatchConfiguration.BatchMaxWait\n\t}\n\n\tif c.BatchConfiguration.BatchQueueSize != 0 {\n\t\trConf.QueueCapacity = c.BatchConfiguration.BatchQueueSize\n\t}\n\n\tif c.BatchConfiguration.CommitInterval != 0 {\n\t\trConf.CommitInterval = c.BatchConfiguration.CommitInterval\n\t}\n\n\tif err := rConf.Validate(); err != nil {\n\t\treturn &kafka.Reader{}, fmt.Errorf(\"while validating reader configuration: %w\", err)\n\t}\n\n\treturn kafka.NewReader(rConf), nil\n}\n","sourceCodeStart":190,"sourceCodeEnd":213,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/kafka/config.go#L190-L213","documentation":"Wraps the error from kafka-go's ReaderConfig.Validate() when building the kafka reader for the datasource. Validate enforces kafka-go's structural rules on the config (e.g. Brokers must not be empty, MinBytes/MaxBytes ordering, GroupID constraints). This surfaces those library-level constraints as part of CrowdSec's kafka source configuration failure.","triggerScenarios":"Configure() (or a direct call to NewReader) with a Configuration whose derived kafka.ReaderConfig fails Validate() — e.g. empty Brokers slipped through, MaxBytes < MinBytes from batch settings, or invalid groupbalancer settings.","commonSituations":"Setting `batch.max_bytes` smaller than `batch.min_bytes` in the acquisition yaml; brokers list emptied by templating/variables that resolved to nothing; kafka-go version differences in Validate rules.","solutions":["Read the wrapped %w Validate() message — it names the exact offending field","Ensure `batch.min_bytes` <= `batch.max_bytes` in the kafka acquisition yaml","Confirm `brokers:` resolves to a non-empty list (check templating/env substitution)","If unsure, temporarily drop batch tuning keys and re-add them one by one to isolate the invalid value"],"exampleFix":"// before\nbatch:\n  min_bytes: 1048576\n  max_bytes: 1024   # max < min -> Validate fails\n// after\nbatch:\n  min_bytes: 1024\n  max_bytes: 1048576","handlingStrategy":"validation","validationCode":"if b := cfg.Batch; b.BatchMaxBytes != 0 && b.BatchMinBytes != 0 && b.BatchMaxBytes < b.BatchMinBytes {\n    return fmt.Errorf(\"batch.max_bytes (%d) must be >= batch.min_bytes (%d)\", b.BatchMaxBytes, b.BatchMinBytes)\n}\nif len(cfg.Brokers) == 0 {\n    return errors.New(\"kafka: brokers list is empty\")\n}","typeGuard":null,"tryCatchPattern":"if err := src.Configure(ctx, yamlCfg, logger, lvl); err != nil {\n    if strings.Contains(err.Error(), \"validating reader configuration\") {\n        logger.Errorf(\"kafka-go rejected the reader config: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep min_bytes <= max_bytes in batch tuning","Verify templated brokers resolve to a non-empty list before startup","Check kafka-go ReaderConfig docs when upgrading the library"],"tags":["kafka","config-validation","kafka-go","crowdsec"],"backgroundTag":"schema-validation-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"}