{"record":{"id":"d62572d979604da1","repo":"apache/beam","slug":"fetch-size-must-be-greater-than-0","errorCode":null,"errorMessage":"fetch size must be greater than 0","messagePattern":"fetch size must be greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/natsio/read_option.go","lineNumber":21,"sourceCode":"// this work for additional information regarding copyright ownership.\n// The ASF licenses this file to You under the Apache License, Version 2.0\n// (the \"License\"); you may not use this file except in compliance with\n// the License.  You may obtain a copy of the License at\n//\n//    http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage natsio\n\nimport \"errors\"\n\nvar (\n\terrInvalidFetchSize  = errors.New(\"fetch size must be greater than 0\")\n\terrInvalidStartSeqNo = errors.New(\"start sequence number must be greater than 0\")\n\terrInvalidEndSeqNo   = errors.New(\"end sequence number must be greater than 0\")\n)\n\ntype readOption struct {\n\tCredsFile  string\n\tTimePolicy timePolicy\n\tFetchSize  int\n\tStartSeqNo int64\n\tEndSeqNo   int64\n}\n\n// ReadOptionFn is a function that can be passed to Read to configure options for reading\n// from NATS.\ntype ReadOptionFn func(option *readOption) error\n\n// ReadUserCredentials sets the user credentials when connecting to NATS.\nfunc ReadUserCredentials(credsFile string) ReadOptionFn {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/natsio/read_option.go#L3-L39","documentation":"errInvalidFetchSize is a sentinel error in the Beam NATS connector returned by the WithFetchSize read option when the requested fetch size is zero or negative. A non-positive fetch size cannot bound how many messages to pull per batch, so the option application fails fast.","triggerScenarios":"Passing natsio.WithFetchSize(0) or a negative int into the read options of a NATS read transform; the error is returned when the option function is applied to readOption.","commonSituations":"Fetch size configured via flags/env with zero default; int overflow or failed parse yielding 0; copy-paste between options where the wrong variable was passed.","solutions":["Pass a strictly positive size, e.g. natsio.WithFetchSize(100).","Validate or default the value before constructing options: if size <= 0 { size = defaultFetchSize }.","Verify the config source actually populated the value instead of leaving it at Go's zero value."],"exampleFix":"// before\nopts = append(opts, natsio.WithFetchSize(fetchSize)) // fetchSize = 0\n// after\nif fetchSize <= 0 {\n    fetchSize = 100\n}\nopts = append(opts, natsio.WithFetchSize(fetchSize))","handlingStrategy":"validation","validationCode":"if fetchSize <= 0 {\n    fetchSize = 100\n}\nopts = append(opts, natsio.WithFetchSize(fetchSize))","typeGuard":null,"tryCatchPattern":"if err := applyReadOptions(opts...); err != nil {\n    if errors.Is(err, errInvalidFetchSize) {\n        return fmt.Errorf(\"configure a positive fetch size: %w\", err)\n    }\n    return err\n}","preventionTips":["Never rely on Go zero values for option ints; set defaults in the option constructor.","Validate NATS read parameters together in one config-loading function.","Document that fetch size is 1-based positive in your wrapper API."],"tags":["go","apache-beam","nats","config-validation"],"backgroundTag":"invalid-config-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}