From 9f48ee396ee0d2d655e9063607e5fbb000d10695 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Tue, 21 Apr 2026 07:48:59 +0000 Subject: [PATCH] fix(librd): reject FetchInfo requests for unknown topics instead of panicking a.fetchInfo silently drops topics that the broker does not return metadata for, so a request like FetchInfo(["does-not-exist"]) used to flow through to admin.DescribeConfigs with an empty resources slice. librd's confluent-kafka-go DescribeConfigs implementation indexes into that slice and crashes with a runtime panic before any error can be surfaced (#19). Compare the size of fetchInfo's result against the requested topic list before building the resources slice. If anything is missing, collect the offending names and return them as a wrapped error so the caller sees a useful 'no metadata returned for topic(s) [...] (do they exist?)' message instead of a runtime crash. Closes #19 Signed-off-by: SAY-5 --- kafka/adaptors/librd/admin.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kafka/adaptors/librd/admin.go b/kafka/adaptors/librd/admin.go index 4be1ac1..ee4366e 100644 --- a/kafka/adaptors/librd/admin.go +++ b/kafka/adaptors/librd/admin.go @@ -83,6 +83,22 @@ func (a *kAdmin) FetchInfo(topics []string) (map[string]*kafka.Topic, error) { return nil, err } + // fetchInfo silently drops topics that the broker does not know + // about. If none of the requested topics resolved, the resources + // slice below stays empty and librd's DescribeConfigs panics with + // an out-of-range index when the empty slice is passed in (#19). + // Surface the missing topics to the caller as an error rather than + // crashing on the next line. + if len(topicInfo) != len(topics) { + var missing []string + for _, t := range topics { + if _, ok := topicInfo[t]; !ok { + missing = append(missing, t) + } + } + return nil, errors.Errorf(`no metadata returned for topic(s) %v (do they exist?)`, missing) + } + for _, meta := range topicInfo { resources = append(resources, librdKafka.ConfigResource{ Type: librdKafka.ResourceTopic,