{"record":{"id":"6378116a144a947e","repo":"apache/beam","slug":"spannerio-query-invalid-option-v","errorCode":null,"errorMessage":"spannerio.Query: invalid option: %v","messagePattern":"spannerio\\.Query: invalid option: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/spannerio/query_options.go","lineNumber":45,"sourceCode":"\n// QueryOptionFn is a function that can be passed to Read or Query to configure options for reading or querying spanner.\ntype QueryOptionFn func(*queryOptions) error\n\n// queryOptions represents additional options for executing a query.\ntype queryOptions struct {\n\tBatching       bool                   `json:\"batching\"`       // Batched reading, default is true.\n\tMaxPartitions  int64                  `json:\"maxPartitions\"`  // Maximum partitions\n\tTimestampBound spanner.TimestampBound `json:\"timestampBound\"` // The TimestampBound to use for batched reading\n}\n\nfunc newQueryOptions(options ...QueryOptionFn) queryOptions {\n\topts := queryOptions{\n\t\tBatching: defaultBatching,\n\t}\n\n\tfor _, opt := range options {\n\t\tif err := opt(&opts); err != nil {\n\t\t\tpanic(fmt.Sprintf(\"spannerio.Query: invalid option: %v\", err))\n\t\t}\n\t}\n\n\treturn opts\n}\n\n// WithBatching sets whether we will use a batched reader. Batching is set to true by default, disable it when the\n// underlying query is not root-partitionable.\nfunc WithBatching(batching bool) QueryOptionFn {\n\treturn func(opts *queryOptions) error {\n\t\topts.Batching = batching\n\t\treturn nil\n\t}\n}\n\n// WithMaxPartitions sets the maximum number of Partitions to split the query into when batched reading.\nfunc WithMaxPartitions(maxPartitions int64) QueryOptionFn {\n\treturn func(opts *queryOptions) error {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/spannerio/query_options.go#L27-L63","documentation":"spannerio's newQueryOptions panics when any applied query option function returns an error, i.e. an invalid QueryOption was passed to spannerio.Read or spannerio.Query. Like natsio, options are validated eagerly at graph-construction time and bad ones are treated as programming errors.","triggerScenarios":"Calling spannerio.Query/Read with an option that errors — e.g. invalid batching parameters (non-positive bytes/rows limits), or an option built for another connector.","commonSituations":"Setting Batching limits to zero or negative values; copying option helpers between spannerio and other io packages; editing an option constructor so it returns a validation error.","solutions":["Check the wrapped error text in the panic to identify the offending option.","Fix the option's values (e.g. positive batching limits) at the call site.","Only use option constructors exported by the spannerio package.","Pre-validate by calling opt(&opts) yourself and checking err before building the pipeline."],"exampleFix":"// before\nspannerio.Query(s, db, q, reflect.TypeOf(Row{}), spannerio.WithBatching(0, 0))\n// after\nspannerio.Query(s, db, q, reflect.TypeOf(Row{}), spannerio.WithBatching(10*1024*1024, 100))","handlingStrategy":"validation","validationCode":"opts := queryOptions{Batching: defaultBatching}\nfor _, opt := range options {\n    if err := opt(&opts); err != nil {\n        return fmt.Errorf(\"invalid spannerio 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, \"spannerio.Query: invalid option\") {\n            // handle\n        } else { panic(r) }\n    }\n}()","preventionTips":["Use only spannerio-exported option constructors.","Ensure batching limits are positive when set.","Dry-run the options in a unit test before building the pipeline."],"tags":["go","apache-beam","spanner","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"}