{"record":{"id":"3a83bdce195f4491","repo":"pathwaycom/pathway","slug":"topic-must-be-a-non-empty-string-got-an-empty-l","errorCode":null,"errorMessage":"'topic' must be a non-empty string; got an empty list. Kafka does not allow empty topic names.","messagePattern":"'topic' must be a non-empty string; got an empty list\\. Kafka does not allow empty topic names\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/kafka/__init__.py","lineNumber":349,"sourceCode":"            )\n            topic = topic_names\n        elif isinstance(topic_names, (list, tuple)):\n            warnings.warn(\n                \"'topic_names' is deprecated; please use 'topic' instead. \"\n                \"Only the first element of the provided list is used as \"\n                \"the topic name.\",\n                DeprecationWarning,\n                stacklevel=_stacklevel + 4,\n            )\n            topic = topic_names[0]\n        else:\n            raise TypeError(\n                f\"'topic_names' must be a str or a list of str; got \"\n                f\"{type(topic_names).__name__}\"\n            )\n    if isinstance(topic, list):\n        if not topic:\n            raise ValueError(\n                \"'topic' must be a non-empty string; got an empty list. \"\n                \"Kafka does not allow empty topic names.\"\n            )\n        warnings.warn(\n            \"'topic' should be a str, not list. First element will be used.\",\n            DeprecationWarning,\n            stacklevel=_stacklevel + 4,\n        )\n        topic = topic[0]\n\n    if not isinstance(topic, str) or not topic:\n        raise ValueError(\n            f\"'topic' must be a non-empty string; got {topic!r}. \"\n            \"Kafka does not allow empty topic names.\"\n        )\n\n    check_deprecated_kwargs(kwargs, [\"topic_names\"], stacklevel=_stacklevel + 4)\n","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/kafka/__init__.py#L331-L367","documentation":"pw.io.kafka.read tolerates a list-valued 'topic' argument for backward compatibility (using the first element with a DeprecationWarning), but an empty list carries no topic at all and is rejected: Kafka does not permit empty topic names, and Pathway raises ValueError before the consumer would fail less clearly.","triggerScenarios":"pw.io.kafka.read(rdkafka_settings, topic=[]) — an empty list is detected before the first-element fallback runs. Contrast with topic=['a'] which only warns, and topic='' which hits the string check instead.","commonSituations":"Building the topic list dynamically (e.g. from an environment variable or subscription registry) and passing it through when it happens to be empty; refactoring code that used to pass a list of topics and now passes zero.","solutions":["Pass a non-empty string: topic='test-topic'.","If topics come from config, validate non-emptiness before calling read and fail with your own actionable message.","Migrate away from list-valued topic entirely — only the first element was ever used."],"exampleFix":"# before\ntopics = []  # populated dynamically, ended up empty\nt = pw.io.kafka.read(rdkafka_settings, topic=topics)\n# after\ntopics = [\"test-topic\"]\nt = pw.io.kafka.read(rdkafka_settings, topic=topics[0])","handlingStrategy":"validation","validationCode":"if isinstance(topic, list):\n    if not topic:\n        raise SystemExit(\"topic list is empty; provide at least one topic name\")\n    topic = topic[0]\n\nt = pw.io.kafka.read(rdkafka_settings, topic=topic)","typeGuard":"def usable_topic(v) -> bool:\n    return (isinstance(v, str) and bool(v)) or (isinstance(v, list) and len(v) > 0)","tryCatchPattern":null,"preventionTips":["Pass topic as a plain string, not a list.","Guard dynamically built topic lists for non-emptiness before calling read."],"tags":["kafka","api-misuse","validation","pathway"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}