{"record":{"id":"11c1c71f5247e6b3","repo":"apache/beam","slug":"exactly-one-of-topic-or-subscription-must-be-provided","errorCode":null,"errorMessage":"Exactly one of topic or subscription must be provided.","messagePattern":"Exactly one of topic or subscription must be provided\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/typescript/src/apache_beam/io/pubsub.ts","lineNumber":61,"sourceCode":"  | {\n      topic: string;\n      subscription?: never;\n      idAttribute?: string;\n      timestampAttribute?: string;\n    }\n  | {\n      topic?: never;\n      subscription: string;\n      idAttribute?: string;\n      timestampAttribute?: string;\n    };\n\n// TODO: Schema-producing variants.\nexport function readFromPubSub(\n  options: ReadOptions,\n): AsyncPTransform<beam.Root, beam.PCollection<Uint8Array>> {\n  if (options.topic && options.subscription) {\n    throw new TypeError(\n      \"Exactly one of topic or subscription must be provided.\",\n    );\n  }\n  return withName(\n    \"readFromPubSubRaw\",\n    external.rawExternalTransform<beam.Root, beam.PCollection<Uint8Array>>(\n      \"beam:transform:org.apache.beam:pubsub_read:v1\",\n      camelToSnakeOptions(options),\n      serviceProviderFromJavaGradleTarget(PUBSUB_EXPANSION_GRADLE_TARGET),\n    ),\n  );\n}\n\nfunction readFromPubSubWithAttributesRaw(\n  options: ReadOptions,\n): AsyncPTransform<beam.Root, beam.PCollection<Uint8Array>> {\n  if (options.topic && options.subscription) {\n    throw new TypeError(","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/typescript/src/apache_beam/io/pubsub.ts#L43-L79","documentation":"readFromPubSub validates its ReadOptions discriminated union up front: both topic and subscription were supplied (or, by the exhausted check, neither), so the reader cannot know which Pub/Sub input to bind. The options object is the input at fault; the type-level mutual exclusion (never on the alternate key) is enforced here at runtime.","triggerScenarios":"Thrown at sdks/typescript/src/apache_beam/io/pubsub.ts:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass exactly one of options.topic or options.subscription to readFromPubSub.","Delete the unused key entirely rather than setting it to null/empty string, since truthiness drives the check.","For subscriptions, prefer the full 'projects/<project>/subscriptions/<sub>' path form."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}