Skip to content

Commit

Permalink
rpk: avoid checking for topic existence with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
r-vasquez committed May 22, 2024
1 parent 30409e4 commit 6736747
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/go/rpk/pkg/cli/topic/consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ func newConsumeCommand(fs afero.Fs, p *config.Params) *cobra.Command {
out.MaybeDie(err, "unable to initialize admin kafka client: %v", err)

// We fail if the topic does not exist.
listed, err := adm.ListTopics(cmd.Context(), topics...)
out.MaybeDie(err, "unable to check topic existence: %v", err)
listed.EachError(func(d kadm.TopicDetail) {
if errors.Is(d.Err, kerr.UnknownTopicOrPartition) {
out.Die("unable to consume topic %q: %v", d.Topic, d.Err.Error())
}
})
if !c.regex {
listed, err := adm.ListTopics(cmd.Context(), topics...)
out.MaybeDie(err, "unable to check topic existence: %v", err)
listed.EachError(func(d kadm.TopicDetail) {
if errors.Is(d.Err, kerr.UnknownTopicOrPartition) {
out.Die("unable to consume topic %q: %v", d.Topic, d.Err.Error())
}
})
}

err = c.parseOffset(offset, topics, adm)
out.MaybeDie(err, "invalid --offset %q: %v", offset, err)
Expand Down

0 comments on commit 6736747

Please sign in to comment.