Repository: apache/kafka
File: core/src/main/scala/kafka/admin/ConfigCommand.scala (Scala)

Code before:
  }

  def describeConfig(adminClient: Admin, opts: ConfigCommandOptions): Unit = {
    val entityTypes = opts.entityTypes
    val entityNames = opts.entityNames
    val describeAll = opts.options.has(opts.allOpt)

    entityTypes.head match {
      case TopicType | BrokerType | BrokerLoggerConfigType | ClientMetricsType | GroupType =>
        describeResourceConfig(adminClient, entityTypes.head, entityNames.headOption, describeAll)
      case UserType | ClientType =>
        describeClientQuotaAndUserScramCredentialConfigs(adminClient, entityTypes, entityNames)
      case IpType =>
        describeQuotaConfigs(adminClient, entityTypes, entityNames)
      case entityType => throw new IllegalArgumentException(s"Invalid entity type: $entityType")
    }
  }

  private def describeResourceConfig(adminClient: Admin, entityType: String, entityName: Option[String], describeAll: Boolean): Unit = {
    if (!describeAll) {
      entityName.foreach { name =>
        entityType match {
          case TopicType =>
            Topic.validate(name)
            if (!adminClient.listTopics(new ListTopicsOptions().listInternal(true)).names.get.contains(name)) {
              System.out.println(s"The $entityType '$name' doesn't exist and doesn't have dynamic config.")
              return
            }
          case BrokerType | BrokerLoggerConfigType =>
            if (adminClient.describeCluster.nodes.get.stream.anyMatch(_.idString == name)) {
              // valid broker id
            } else if (name == BrokerDefaultEntityName) {
              // default broker configs
            } else {
              System.out.println(s"The $entityType '$name' doesn't exist and doesn't have dynamic config.")
              return
            }
          case ClientMetricsType =>
            if (adminClient.listConfigResources(java.util.Set.of(ConfigResource.Type.CLIENT_METRICS), new ListConfigResourcesOptions).all.get
              .stream.noneMatch(_.name == name)) {
              System.out.println(s"The $entityType '$name' doesn't exist and doesn't have dynamic config.")
              return
            }
          case GroupType =>
            if (adminClient.listGroups().all.get.stream.noneMatch(_.groupId() == name) &&
              adminClient.listConfigResources(java.util.Set.of(ConfigResource.Type.GROUP), new ListConfigResourcesOptions).all.get
                .stream.noneMatch(_.name == name)) {
              System.out.println(s"The $entityType '$name' doesn't exist and doesn't have dynamic config.")
              return
            }
          case entityType => throw new IllegalArgumentException(s"Invalid entity type: $entityType")

Review comment (suggestion):
The variable `entityType` contains the pluralized noun such as topics or groups. As a result, the message is not grammatical, for example `The groups 'G2' doesn't exist and doesn't have dynamic config.`. This problem is evident for all entity types.

Probably easiest here is just to use a slightly different string for each type such as `s"The topic '$name' doesn't exist and doesn't have dynamic config."`.

Code after:
  }

  def describeConfig(adminClient: Admin, opts: ConfigCommandOptions): Unit = {
    val entityTypes = opts.entityTypes
    val entityNames = opts.entityNames
    val describeAll = opts.options.has(opts.allOpt)

    entityTypes.head match {
      case TopicType | BrokerType | BrokerLoggerConfigType | ClientMetricsType | GroupType =>
        describeResourceConfig(adminClient, entityTypes.head, entityNames.headOption, describeAll)
      case UserType | ClientType =>
        describeClientQuotaAndUserScramCredentialConfigs(adminClient, entityTypes, entityNames)
      case IpType =>
        describeQuotaConfigs(adminClient, entityTypes, entityNames)
      case entityType => throw new IllegalArgumentException(s"Invalid entity type: $entityType")
    }
  }

  private def describeResourceConfig(adminClient: Admin, entityType: String, entityName: Option[String], describeAll: Boolean): Unit = {
    if (!describeAll) {
      entityName.foreach { name =>
        entityType match {
          case TopicType =>
            Topic.validate(name)
            if (!adminClient.listTopics(new ListTopicsOptions().listInternal(true)).names.get.contains(name)) {
              System.out.println(s"The ${entityType.dropRight(1)} '$name' doesn't exist and doesn't have dynamic config.")
              return
            }
          case BrokerType | BrokerLoggerConfigType =>
            if (adminClient.describeCluster.nodes.get.stream.anyMatch(_.idString == name)) {
              // valid broker id
            } else if (name == BrokerDefaultEntityName) {
              // default broker configs
            } else {
              System.out.println(s"The ${entityType.dropRight(1)} '$name' doesn't exist and doesn't have dynamic config.")
              return
            }
          case ClientMetricsType =>
            if (adminClient.listConfigResources(java.util.Set.of(ConfigResource.Type.CLIENT_METRICS), new ListConfigResourcesOptions).all.get
              .stream.noneMatch(_.name == name)) {
              System.out.println(s"The ${entityType.dropRight(1)} '$name' doesn't exist and doesn't have dynamic config.")
              return
            }
          case GroupType =>
            if (adminClient.listGroups().all.get.stream.noneMatch(_.groupId() == name) &&
              adminClient.listConfigResources(java.util.Set.of(ConfigResource.Type.GROUP), new ListConfigResourcesOptions).all.get
                .stream.noneMatch(_.name == name)) {
              System.out.println(s"The ${entityType.dropRight(1)} '$name' doesn't exist and doesn't have dynamic config.")
              return
            }
          case entityType => throw new IllegalArgumentException(s"Invalid entity type: $entityType")