apache/beam · error

mongodbio.Read: invalid option: %v

Error message

mongodbio.Read: invalid option: %v

What it means

mongodbio.Read validates every variadic ReadOption by invoking it and checking the returned error. If any option func returns an error, Read panics because options are expected to be statically correct at graph-construction time. This converts option-apply errors into a fail-fast at pipeline build.

Source

Thrown at sdks/go/pkg/beam/io/mongodbio/read.go:82

//   - BundleSize: the size in bytes to bundle the documents into when reading. Defaults to
//     64 * 1024 * 1024 (64 MB)
func Read(
	s beam.Scope,
	uri string,
	database string,
	collection string,
	t reflect.Type,
	opts ...ReadOptionFn,
) beam.PCollection {
	s = s.Scope("mongodbio.Read")

	option := &ReadOption{
		BundleSize: defaultReadBundleSize,
	}

	for _, opt := range opts {
		if err := opt(option); err != nil {
			panic(fmt.Sprintf("mongodbio.Read: invalid option: %v", err))
		}
	}

	imp := beam.Impulse(s)

	return beam.ParDo(
		s,
		newReadFn(uri, database, collection, t, option),
		imp,
		beam.TypeDefinition{Var: beam.YType, T: t},
	)
}

type readFn struct {
	mongoDBFn
	BucketAuto bool
	BundleSize int64
	Filter     []byte

View on GitHub (pinned to 12126d8942)

Solutions

  1. Fix the input the option validates (positive bundle size, valid BSON filter document)
  2. Review any custom ReadOption func for incorrect validation or a bug returning error
  3. Validate inputs (bundle size > 0, filter marshals to bson.M) before calling Read
  4. Wrap pipeline construction in recover() to report the message cleanly

Example fix

// before
opt := func(o *mongodbio.ReadOption) error {
    o.BundleSize = cfg.BundleSize // cfg.BundleSize = -1
    return nil
}
// after
opt := func(o *mongodbio.ReadOption) error {
    if cfg.BundleSize <= 0 {
        return fmt.Errorf("bundleSize must be > 0, got %d", cfg.BundleSize)
    }
    o.BundleSize = cfg.BundleSize
    return nil
}
Defensive patterns

Strategy: validation

Validate before calling

func validateReadOption(o *mongodbio.ReadOption) error {
    if o.BundleSize <= 0 { return fmt.Errorf("BundleSize must be > 0") }
    return nil
}

Try / catch

defer func() { if r := recover(); r != nil { log.Fatalf("Read options invalid: %v", r) } }()

Prevention

When it happens

Trigger: Passing a custom func(*ReadOption) error that returns non-nil, e.g. a WithBundleSize-style helper validating BundleSize <= 0 or an invalid Filter encoding option, when constructing the pipeline.

Common situations: Hand-written option funcs with bad validation logic; options built from user flags (negative bundle size, malformed filter JSON) that fail validation at pipeline start.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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