{"record":{"id":"09ec3721a2fd276e","repo":"apache/beam","slug":"to-read-from-pubsub-a-subscription-name-or-a-topic-name-must","errorCode":null,"errorMessage":"To read from Pubsub, a subscription name or a topic name must be provided","messagePattern":"To read from Pubsub, a subscription name or a topic name must be provided","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubReadSchemaTransformProvider.java","lineNumber":79,"sourceCode":"\n  public static final String VALID_FORMATS_STR = \"RAW,AVRO,JSON\";\n  public static final Set<String> VALID_DATA_FORMATS =\n      Sets.newHashSet(VALID_FORMATS_STR.split(\",\"));\n\n  public static final TupleTag<Row> OUTPUT_TAG = new TupleTag<Row>() {};\n  public static final TupleTag<Row> ERROR_TAG = new TupleTag<Row>() {};\n  public static final Schema ERROR_SCHEMA =\n      Schema.builder().addStringField(\"error\").addNullableByteArrayField(\"row\").build();\n\n  @Override\n  public Class<PubsubReadSchemaTransformConfiguration> configurationClass() {\n    return PubsubReadSchemaTransformConfiguration.class;\n  }\n\n  @Override\n  public SchemaTransform from(PubsubReadSchemaTransformConfiguration configuration) {\n    if (configuration.getSubscription() == null && configuration.getTopic() == null) {\n      throw new IllegalArgumentException(\n          \"To read from Pubsub, a subscription name or a topic name must be provided\");\n    }\n\n    if (configuration.getSubscription() != null && configuration.getTopic() != null) {\n      throw new IllegalArgumentException(\n          \"To read from Pubsub, a subscription name or a topic name must be provided. Not both.\");\n    }\n\n    if (!\"RAW\".equals(configuration.getFormat())) {\n      if ((Strings.isNullOrEmpty(configuration.getSchema())\n              && !Strings.isNullOrEmpty(configuration.getFormat()))\n          || (!Strings.isNullOrEmpty(configuration.getSchema())\n              && Strings.isNullOrEmpty(configuration.getFormat()))) {\n        throw new IllegalArgumentException(\n            \"A schema was provided without a data format (or viceversa). Please provide \"\n                + \"both of these parameters to read from Pubsub, or if you would like to use the Pubsub schema service,\"\n                + \" please leave both of these blank.\");\n      }","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubReadSchemaTransformProvider.java#L61-L97","documentation":"PubsubReadSchemaTransformProvider.from() validates its configuration before building the SchemaTransform. A read needs exactly one of a subscription or a topic; if both are null it throws IllegalArgumentException with this message.","triggerScenarios":"Creating a Pubsub read SchemaTransform via PubsubReadSchemaTransformProvider.from(configuration) with a configuration object where neither getSubscription() nor getTopic() is set — e.g. empty YAML/config mapping or programmatically built configuration with no fields populated.","commonSituations":"YAML pipeline definitions missing the 'subscription' or 'topic' key, typo'd config keys (e.g. 'topicName'), or building the configuration bean in Java and forgetting setSubscription()/setTopic().","solutions":["Set exactly one of subscription or topic in the configuration (YAML key 'subscription' or 'topic').","Check for typo'd or ignored config keys so the value actually lands on the configuration object.","When setting programmatically, call configuration.setTopic(...) or setSubscription(...) before from()."],"exampleFix":"// before\nmap:\n  format: JSON   # no subscription/topic\n// after\nmap:\n  subscription: projects/my-project/subscriptions/my-sub\n  format: JSON","handlingStrategy":"validation","validationCode":"PubsubReadSchemaTransformConfiguration c = ...;\nif (c.getSubscription() == null && c.getTopic() == null) {\n  throw new IllegalArgumentException(\"Set exactly one of subscription or topic for Pubsub read\");\n}\nif (c.getSubscription() != null && c.getTopic() != null) {\n  throw new IllegalArgumentException(\"Set subscription OR topic, not both\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  transform = provider.from(configuration);\n} catch (IllegalArgumentException e) {\n  // populate subscription or topic in the config and retry\n}","preventionTips":["Specify exactly one of subscription/topic in YAML or code","Watch for typo'd config keys that silently drop the value","Validate configuration objects before calling from()"],"tags":["java","pubsub","beam","schema-transform","configuration"],"backgroundTag":"missing-required-config-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}