{"record":{"id":"585cf922483fe485","repo":"crowdsecurity/crowdsec","slug":"cannot-create-a-s-reader-with-an-empty-list-of-br","errorCode":null,"errorMessage":"cannot create a %s reader with an empty list of broker addresses","messagePattern":"cannot create a (.+?) reader with an empty list of broker addresses","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/kafka/config.go","lineNumber":56,"sourceCode":"\ntype KafkaBatchConfiguration struct {\n\tBatchMinBytes  int           `yaml:\"min_bytes\"`\n\tBatchMaxBytes  int           `yaml:\"max_bytes\"`\n\tBatchMaxWait   time.Duration `yaml:\"max_wait\"`\n\tBatchQueueSize int           `yaml:\"queue_size\"`\n\tCommitInterval time.Duration `yaml:\"commit_interval\"`\n}\n\nfunc (s *Source) UnmarshalConfig(yamlConfig []byte) error {\n\ts.Config = Configuration{}\n\n\terr := yaml.UnmarshalWithOptions(yamlConfig, &s.Config, yaml.Strict())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot parse: %s\", yaml.FormatError(err, false, false))\n\t}\n\n\tif len(s.Config.Brokers) == 0 {\n\t\treturn fmt.Errorf(\"cannot create a %s reader with an empty list of broker addresses\", s.GetName())\n\t}\n\n\tif s.Config.Topic == \"\" {\n\t\treturn fmt.Errorf(\"cannot create a %s reader with an empty topic\", s.GetName())\n\t}\n\n\tif s.Config.Mode == \"\" {\n\t\ts.Config.Mode = configuration.TAIL_MODE\n\t}\n\n\ts.logger.Debugf(\"successfully parsed kafka configuration : %+v\", s.Config)\n\n\treturn err\n}\n\nfunc (s *Source) Configure(_ context.Context, yamlConfig []byte, logger *log.Entry, metricsLevel metrics.AcquisitionMetricsLevel) error {\n\ts.logger = logger\n\ts.metricsLevel = metricsLevel","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/kafka/config.go#L38-L74","documentation":"After parsing the kafka source config, UnmarshalConfig requires at least one broker address in the 'brokers' list. An empty or missing brokers list means the reader has nothing to connect to, so configuration is rejected with this message (the %s is the source name, 'kafka').","triggerScenarios":"Source.UnmarshalConfig receiving a kafka YAML block with no 'brokers' key, an empty list ('brokers: []'), or a list containing only empty strings.","commonSituations":"Minimal example configs copied without the brokers line; templating that left the brokers field empty; forgetting to configure brokers because topic was set.","solutions":["Add at least one broker to the config: brokers: [kafka1:9092].","If brokers come from templating/env, verify the variable is populated at render time.","Ensure each entry is a host:port reachable from the crowdsec host.","Remove empty-string entries from the brokers list."],"exampleFix":"// before\nsource: kafka\ntopic: crowdsec\n// after\nsource: kafka\nbrokers:\n  - localhost:9092\ntopic: crowdsec","handlingStrategy":"validation","validationCode":"var kc struct {\n    Brokers []string `yaml:\"brokers\"`\n}\nif err := yaml.Unmarshal(yamlCfg, &kc); err != nil { return err }\nnonEmpty := 0\nfor _, b := range kc.Brokers { if strings.TrimSpace(b) != \"\" { nonEmpty++ } }\nif nonEmpty == 0 { return errors.New(\"kafka source requires at least one broker\") }","typeGuard":null,"tryCatchPattern":"if err := source.UnmarshalConfig(cfg); err != nil {\n    if strings.Contains(err.Error(), \"empty list of broker addresses\") {\n        // inject brokers from env/templating and retry\n    }\n}","preventionTips":["Always include at least one brokers entry in kafka acquis blocks","Verify templated/env-provided broker values are non-empty at render time","Reachability-check each host:port before deployment"],"tags":["go","kafka","configuration","brokers"],"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-14T05:17:10.506Z"}