{"record":{"id":"dc94e8ea56c01055","repo":"t8y2/dbx","slug":"topic-is-required-when-producergroup-is-specified","errorCode":null,"errorMessage":"topic is required when producerGroup is specified","messagePattern":"topic is required when producerGroup is specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rocketmq/messages.go","lineNumber":39,"sourceCode":"type messageQueueTarget struct {\n\tBrokerName string\n\tAddress    string\n\tQueueID    int\n}\n\nfunc (a *rocketMQAgent) listProducers(params map[string]any) (any, error) {\n\tclient, config, err := a.requireClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), config.RequestTimeout)\n\tdefer cancel()\n\ttopic := stringValue(params, \"topic\")\n\tproducerGroup := stringValue(params, \"producerGroup\", \"group\")\n\trows := make([]map[string]any, 0)\n\tif producerGroup != \"\" {\n\t\tif topic == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"topic is required when producerGroup is specified\")\n\t\t}\n\t\tconnection, queryErr := client.ExamineProducerConnectionInfo(ctx, producerGroup, topic)\n\t\tif queryErr != nil {\n\t\t\treturn nil, queryErr\n\t\t}\n\t\tfor index, connectionInfo := range connection.ConnectionSet {\n\t\t\trows = append(rows, producerRow(int64(index+1), producerGroup, connectionInfo))\n\t\t}\n\t\treturn map[string]any{\"producers\": rows}, nil\n\t}\n\n\taddresses := make([]string, 0)\n\tif topic != \"\" {\n\t\tstats, statsErr := a.examineTopicStats(ctx, client, topic)\n\t\tif statsErr != nil {\n\t\t\treturn nil, statsErr\n\t\t}\n\t\thasMessages := false","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rocketmq/messages.go#L21-L57","documentation":"listProducers can query producer connections either by topic or by producerGroup, but the admin API ExamineProducerConnectionInfo always needs both. When 'producerGroup' (alias 'group') is specified without 'topic', the driver refuses the call with 'topic is required when producerGroup is specified'. This is a precondition check before the broker call.","triggerScenarios":"Calling the listProducers dispatch operation with {\"producerGroup\": \"PID_xxx\"} and no 'topic' key (or an empty topic), intending to enumerate all topics for a group.","commonSituations":"Assuming group-only listing is supported (like consumer group inspection); building a UI where the topic field is optional; migrating code from another admin tool that supported group-only queries.","solutions":["Pass the 'topic' alongside 'producerGroup' — the query is per (group, topic) pair.","If you need all topics for a group, first list topics (topic list operation) then call listProducers per topic.","Remove 'producerGroup' entirely to fall back to topic-only listing, if that matches your intent.","Ensure the topic value isn't an empty string from upstream config."],"exampleFix":"// before\nrows, err := agent.ListProducers(ctx, map[string]any{\"producerGroup\": \"PID_demo\"})\n// after\nrows, err := agent.ListProducers(ctx, map[string]any{\"producerGroup\": \"PID_demo\", \"topic\": \"demo-topic\"})","handlingStrategy":"validation","validationCode":"group, _ := params[\"producerGroup\"].(string)\nif group == \"\" { group, _ = params[\"group\"].(string) }\ntopic, _ := params[\"topic\"].(string)\nif group != \"\" && topic == \"\" {\n    return errors.New(\"topic is required when producerGroup is specified\")\n}","typeGuard":"func producerQueryValid(params map[string]any) bool {\n    g := coalesce(params, \"producerGroup\", \"group\")\n    t := coalesce(params, \"topic\")\n    return g == \"\" || t != \"\"\n}","tryCatchPattern":"rows, err := agent.ListProducers(ctx, params)\nif err != nil && strings.Contains(err.Error(), \"topic is required when producerGroup\") {\n    // fix input: enumerate topics first, then query per (group, topic)\n}","preventionTips":["Remember ExamineProducerConnectionInfo is always (group, topic)-scoped; never send group alone.","To enumerate all producers of a group, loop over the topic list.","Make 'topic' a required field in forms/APIs that accept producerGroup.","Guard against empty-string topics from optional UI inputs."],"tags":["validation","missing-parameter","rocketmq","admin-api"],"backgroundTag":"missing-required-parameter","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}