{"record":{"id":"9348ce8c8d62ef5f","repo":"apache/beam","slug":"end-sequence-number-must-be-greater-than-0","errorCode":null,"errorMessage":"end sequence number must be greater than 0","messagePattern":"end sequence number must be greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/natsio/read_option.go","lineNumber":23,"sourceCode":"// (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 {\n\treturn func(o *readOption) error {\n\t\to.CredsFile = credsFile","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/natsio/read_option.go#L5-L41","documentation":"errInvalidEndSeqNo is a sentinel error returned by the WithEndSeqNo NATS read option when the ending sequence number is zero or negative. Since NATS sequences are 1-based, an end bound must be at least 1 for the read range to be valid.","triggerScenarios":"Passing natsio.WithEndSeqNo(0) or a negative value into the read options, e.g. from an unset configuration value or a range computation that produced an empty/invalid upper bound.","commonSituations":"Reading a bounded range [start, end] where end was computed as start-1 or left at 0; missing flag/env for the end sequence; off-by-one when computing the last sequence to replay.","solutions":["Pass an end sequence >= 1, ensuring end >= start for a non-empty range.","Validate range math before constructing options: if end <= 0, either omit the option (unbounded) or set the latest known sequence.","Check the config source that supplies the end sequence for zero defaults."],"exampleFix":"// before\nopts = append(opts, natsio.WithEndSeqNo(end)) // end = 0 from missing config\n// after\nif end <= 0 {\n    return fmt.Errorf(\"end sequence must be configured\")\n}\nopts = append(opts, natsio.WithEndSeqNo(end))","handlingStrategy":"validation","validationCode":"if endSeq <= 0 || endSeq < startSeq {\n    return fmt.Errorf(\"endSeq must be >= 1 and >= startSeq (%d), got %d\", startSeq, endSeq)\n}\nopts = append(opts, natsio.WithEndSeqNo(endSeq))","typeGuard":null,"tryCatchPattern":"if err := applyReadOptions(opts...); err != nil {\n    if errors.Is(err, errInvalidEndSeqNo) {\n        return fmt.Errorf(\"end sequence must be >= 1: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate the whole [start, end] range before constructing options.","Compute end bounds from stream info (last sequence) instead of hardcoded 0.","Guard off-by-one arithmetic when deriving end from start + count."],"tags":["go","apache-beam","nats","sequence-number","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"}