[ https://issues.apache.org/jira/browse/KAFKA-8670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16885704#comment-16885704 ]
ASF GitHub Bot commented on KAFKA-8670: --------------------------------------- wyuka commented on pull request #7094: KAFKA-8670 and KAFKA-8053: Fix kafka-topics.sh --describe without --t… URL: https://github.com/apache/kafka/pull/7094 …opic mentioned if there are no topics in cluster; improve error message. If there are no topics in a cluster, kafka-topics.sh --describe without a --topic option should return empty list, do not throw an exception. If there are no matching topics, throw IllegalArgumentException but with better error message. ### KAFKA-8670 We pass a boolean flag to `ensureTopicExists` method indicating whether to throw an exception if there are no topics in the cluster. In case of `kafka-topics.sh --describe`, the exception **should NOT** be thrown if either of these are true - 1. A `--topic` option was not passed to the CLI. In that case, the output should be empty. 2. A `--if-exists` option was passed to the CLI. Earlier, the first condition was not part of the check. This bugfix adds the first condition mentioned above to the check. ### KAFKA-8053 Earlier, when `./kafka-topics.sh` was run with a `--topic` argument that was not found in the list of topics, the exception message was always "Topics in [] does not exist". This was a useless message. I have changed it to "No topic matching <topic name> found". *Summary of testing strategy (including rationale) for the feature or bug fix. Unit and/or integration tests are expected for any behaviour change and system tests should be considered for larger changes.* I added the necessary unit test to check for this case. Also, I ran these commands. The output before and after my change are mentioned inline **Describe without topic name - Before** ``` ./kafka-topics.sh --zookeeper 10.0.32.180:2181,10.0.16.211:2181,10.0.0.220:2181 --describe Error while executing topic command : Topics in [] does not exist [2019-07-15 23:23:25,674] ERROR java.lang.IllegalArgumentException: Topics in [] does not exist at kafka.admin.TopicCommand$.kafka$admin$TopicCommand$$ensureTopicExists(TopicCommand.scala:416) at kafka.admin.TopicCommand$ZookeeperTopicService.describeTopic(TopicCommand.scala:332) at kafka.admin.TopicCommand$.main(TopicCommand.scala:66) at kafka.admin.TopicCommand.main(TopicCommand.scala) (kafka.admin.TopicCommand$) ``` **Describe without topic name - After (no output)** ``` ./kafka-topics.sh --zookeeper 10.0.32.180:2181,10.0.16.211:2181,10.0.0.220:2181 --describe ``` **Describe with topic name - Before** ``` ./kafka-topics.sh --zookeeper 10.0.32.180:2181,10.0.16.211:2181,10.0.0.220:2181 --describe --topic topic-1 Error while executing topic command : Topics in [] does not exist [2019-07-15 23:23:36,152] ERROR java.lang.IllegalArgumentException: Topics in [] does not exist at kafka.admin.TopicCommand$.kafka$admin$TopicCommand$$ensureTopicExists(TopicCommand.scala:416) at kafka.admin.TopicCommand$ZookeeperTopicService.describeTopic(TopicCommand.scala:332) at kafka.admin.TopicCommand$.main(TopicCommand.scala:66) at kafka.admin.TopicCommand.main(TopicCommand.scala) (kafka.admin.TopicCommand$) ``` **Describe with topic name - After** ``` Error while executing topic command : No topic matching name 'topic-1' found [2019-07-15 23:24:55,169] ERROR java.lang.IllegalArgumentException: No topic matching 'topic-1' found at kafka.admin.TopicCommand$.kafka$admin$TopicCommand$$ensureTopicExists(TopicCommand.scala:445) at kafka.admin.TopicCommand$ZookeeperTopicService.describeTopic(TopicCommand.scala:358) at kafka.admin.TopicCommand$.main(TopicCommand.scala:67) at kafka.admin.TopicCommand.main(TopicCommand.scala) (kafka.admin.TopicCommand$) ``` ### Committer Checklist (excluded from commit message) - [ ] Verify design and implementation - [ ] Verify test coverage and CI build status - [ ] Verify documentation (including upgrade notes) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > kafka-topics.sh shows IllegalArgumentException when describing all topics if > no topics exist on the cluster > ----------------------------------------------------------------------------------------------------------- > > Key: KAFKA-8670 > URL: https://issues.apache.org/jira/browse/KAFKA-8670 > Project: Kafka > Issue Type: Bug > Components: admin, tools > Affects Versions: 2.2.0, 2.3.0, 2.2.1 > Reporter: Tirtha Chatterjee > Assignee: Tirtha Chatterjee > Priority: Major > > When trying to describe all the kafka-topics.sh utility, a user would run > kafka-topics.sh --describe without passing a --topic option. If there are no > topics on the cluster, Kafka returns an error with IllegalArgumentException. > {code:java} > ./kafka-topics.sh --zookeeper > 172.16.7.230:2181,172.16.17.27:2181,172.16.10.89:2181 --describe > Error while executing topic command : Topics in [] does not exist > [2019-07-07 03:33:15,288] ERROR java.lang.IllegalArgumentException: Topics in > [] does not exist > at > kafka.admin.TopicCommand$.kafka$admin$TopicCommand$$ensureTopicExists(TopicCommand.scala:416) > at > kafka.admin.TopicCommand$ZookeeperTopicService.describeTopic(TopicCommand.scala:332) > at kafka.admin.TopicCommand$.main(TopicCommand.scala:66) > at kafka.admin.TopicCommand.main(TopicCommand.scala) > (kafka.admin.TopicCommand$) > {code} > > If no --topic option is passed to the command, and there are no topics on > the cluster, the command should not fail, rather have empty output. -- This message was sent by Atlassian JIRA (v7.6.14#76016)