apache/beam · error · TypeError

Exactly one of topic or subscription must be provided.

Error message

Exactly one of topic or subscription must be provided.

What it means

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.

Solutions

  1. Pass exactly one of options.topic or options.subscription to readFromPubSub.
  2. Delete the unused key entirely rather than setting it to null/empty string, since truthiness drives the check.
  3. For subscriptions, prefer the full 'projects/<project>/subscriptions/<sub>' path form.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at sdks/typescript/src/apache_beam/io/pubsub.ts:61 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/11c1c71f5247e6b3. Report an issue: GitHub.

Appendix: source

Thrown at sdks/typescript/src/apache_beam/io/pubsub.ts:61

  | {
      topic: string;
      subscription?: never;
      idAttribute?: string;
      timestampAttribute?: string;
    }
  | {
      topic?: never;
      subscription: string;
      idAttribute?: string;
      timestampAttribute?: string;
    };

// TODO: Schema-producing variants.
export function readFromPubSub(
  options: ReadOptions,
): AsyncPTransform<beam.Root, beam.PCollection<Uint8Array>> {
  if (options.topic && options.subscription) {
    throw new TypeError(
      "Exactly one of topic or subscription must be provided.",
    );
  }
  return withName(
    "readFromPubSubRaw",
    external.rawExternalTransform<beam.Root, beam.PCollection<Uint8Array>>(
      "beam:transform:org.apache.beam:pubsub_read:v1",
      camelToSnakeOptions(options),
      serviceProviderFromJavaGradleTarget(PUBSUB_EXPANSION_GRADLE_TARGET),
    ),
  );
}

function readFromPubSubWithAttributesRaw(
  options: ReadOptions,
): AsyncPTransform<beam.Root, beam.PCollection<Uint8Array>> {
  if (options.topic && options.subscription) {
    throw new TypeError(

View on GitHub (pinned to 12126d8942)