{"record":{"id":"3f291066792cfa82","repo":"apache/beam","slug":"mongodbio-read-invalid-option-v","errorCode":null,"errorMessage":"mongodbio.Read: invalid option: %v","messagePattern":"mongodbio\\.Read: invalid option: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/mongodbio/read.go","lineNumber":82,"sourceCode":"//   - BundleSize: the size in bytes to bundle the documents into when reading. Defaults to\n//     64 * 1024 * 1024 (64 MB)\nfunc Read(\n\ts beam.Scope,\n\turi string,\n\tdatabase string,\n\tcollection string,\n\tt reflect.Type,\n\topts ...ReadOptionFn,\n) beam.PCollection {\n\ts = s.Scope(\"mongodbio.Read\")\n\n\toption := &ReadOption{\n\t\tBundleSize: defaultReadBundleSize,\n\t}\n\n\tfor _, opt := range opts {\n\t\tif err := opt(option); err != nil {\n\t\t\tpanic(fmt.Sprintf(\"mongodbio.Read: invalid option: %v\", err))\n\t\t}\n\t}\n\n\timp := beam.Impulse(s)\n\n\treturn beam.ParDo(\n\t\ts,\n\t\tnewReadFn(uri, database, collection, t, option),\n\t\timp,\n\t\tbeam.TypeDefinition{Var: beam.YType, T: t},\n\t)\n}\n\ntype readFn struct {\n\tmongoDBFn\n\tBucketAuto bool\n\tBundleSize int64\n\tFilter     []byte","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/mongodbio/read.go#L64-L100","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the input the option validates (positive bundle size, valid BSON filter document)","Review any custom ReadOption func for incorrect validation or a bug returning error","Validate inputs (bundle size > 0, filter marshals to bson.M) before calling Read","Wrap pipeline construction in recover() to report the message cleanly"],"exampleFix":"// before\nopt := func(o *mongodbio.ReadOption) error {\n    o.BundleSize = cfg.BundleSize // cfg.BundleSize = -1\n    return nil\n}\n// after\nopt := func(o *mongodbio.ReadOption) error {\n    if cfg.BundleSize <= 0 {\n        return fmt.Errorf(\"bundleSize must be > 0, got %d\", cfg.BundleSize)\n    }\n    o.BundleSize = cfg.BundleSize\n    return nil\n}","handlingStrategy":"validation","validationCode":"func validateReadOption(o *mongodbio.ReadOption) error {\n    if o.BundleSize <= 0 { return fmt.Errorf(\"BundleSize must be > 0\") }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Fatalf(\"Read options invalid: %v\", r) } }()","preventionTips":["Keep option funcs pure and well-tested","Validate user flags feeding options before pipeline construction","Prefer library-provided option constructors over hand-rolled closures"],"tags":["go","mongodb","panic","options"],"backgroundTag":"invalid-argument-value","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"}