{"record":{"id":"55edd96d6bc383b8","repo":"apache/beam","slug":"natsio-read-invalid-option-v","errorCode":null,"errorMessage":"natsio.Read: invalid option: %v","messagePattern":"natsio\\.Read: invalid option: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/natsio/read.go","lineNumber":89,"sourceCode":"func Read(\n\ts beam.Scope,\n\turi string,\n\tstream string,\n\tsubject string,\n\topts ...ReadOptionFn,\n) beam.PCollection {\n\ts = s.Scope(\"natsio.Read\")\n\n\toption := &readOption{\n\t\tTimePolicy: processingTimePolicy,\n\t\tFetchSize:  defaultFetchSize,\n\t\tStartSeqNo: defaultStartSeqNo,\n\t\tEndSeqNo:   defaultEndSeqNo,\n\t}\n\n\tfor _, opt := range opts {\n\t\tif err := opt(option); err != nil {\n\t\t\tpanic(fmt.Sprintf(\"natsio.Read: invalid option: %v\", err))\n\t\t}\n\t}\n\n\timp := beam.Impulse(s)\n\treturn beam.ParDo(s, newReadFn(uri, stream, subject, option), imp)\n}\n\ntype readFn struct {\n\tnatsFn\n\tStream      string\n\tSubject     string\n\tTimePolicy  timePolicy\n\tFetchSize   int\n\tStartSeqNo  int64\n\tEndSeqNo    int64\n\ttimestampFn timestampFn\n}\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/natsio/read.go#L71-L107","documentation":"natsio.Read panics when an option function passed to it returns an error, meaning an invalid ReadOption was supplied. This library validates options eagerly at pipeline-construction time and treats a bad option as a programmer error, so it panics instead of returning an error. The panic happens before any distributed work starts.","triggerScenarios":"Calling natsio.Read(s, uri, stream, subject, someInvalidOption()) where an option function (e.g. one built with wrong bounds, negative values, or a misused option constructor) returns a non-nil error from opt(option).","commonSituations":"Passing an option constructed for a different io connector into natsio.Read; misconfiguring sequence numbers (StartSeqNo > EndSeqNo); copying example code and editing an option helper so it returns an error.","solutions":["Check which option in the variadic list returns an error; the wrapped error text is included in the panic message.","Fix the option's parameters (e.g. valid sequence-number ranges) at the call site.","Only pass options produced by this package's exported option constructors.","If the panic is undesirable, validate options yourself by invoking opt(option) and checking err before calling Read."],"exampleFix":"// before\nbeam.ParDo(s, newReadFn(uri, stream, subject, option), imp) // option built with bad value\n// after\nopt := natsio.WithStartSeqNo(1) // use exported constructors with valid values\nif err := opt(option); err != nil {\n    return fmt.Errorf(\"bad nats option: %w\", err)\n}\nnatsio.Read(s, uri, stream, subject, opt)","handlingStrategy":"validation","validationCode":"for _, opt := range opts {\n    if err := opt(option); err != nil {\n        return fmt.Errorf(\"invalid natsio option: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if s, ok := r.(string); ok && strings.Contains(s, \"natsio.Read: invalid option\") {\n            // handle\n        } else { panic(r) }\n    }\n}()","preventionTips":["Only use exported natsio option constructors with valid values.","Dry-run option application in a unit test before building the pipeline.","Check sequence-number ranges (Start <= End) before passing them."],"tags":["go","apache-beam","nats","panic","invalid-option"],"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"}