{"record":{"id":"a1d47d93480eb2e4","repo":"nats-io/nats-server","slug":"errsetnotempty","errorCode":"ErrSetNotEmpty","errorMessage":"ss: set not empty","messagePattern":"ss: set not empty","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/avl/seqset.go","lineNumber":309,"sourceCode":"\ti += 8\n\tss.root.nodeIter(func(n *node) {\n\t\tle.PutUint64(buf[i:], n.base)\n\t\ti += 8\n\t\tfor _, b := range n.bits {\n\t\t\tle.PutUint64(buf[i:], b)\n\t\t\ti += 8\n\t\t}\n\t\tle.PutUint16(buf[i:], uint16(n.h))\n\t\ti += 2\n\t})\n\treturn buf[:i]\n}\n\n// ErrBadEncoding is returned when we can not decode properly.\nvar (\n\tErrBadEncoding = errors.New(\"ss: bad encoding\")\n\tErrBadVersion  = errors.New(\"ss: bad version\")\n\tErrSetNotEmpty = errors.New(\"ss: set not empty\")\n)\n\n// Decode returns the sequence set and number of bytes read from the buffer on success.\nfunc Decode(buf []byte) (*SequenceSet, int, error) {\n\tif len(buf) < minLen || buf[0] != magic {\n\t\treturn nil, -1, ErrBadEncoding\n\t}\n\n\tswitch v := buf[1]; v {\n\tcase 1:\n\t\treturn decodev1(buf)\n\tcase 2:\n\t\treturn decodev2(buf)\n\tdefault:\n\t\treturn nil, -1, ErrBadVersion\n\t}\n}\n","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/avl/seqset.go#L291-L327","documentation":"ErrSetNotEmpty is returned by SequenceSet.SetInitialMin when the set already contains values. SetInitialMin can only initialize a fresh, empty set with a starting minimum, so calling it on a populated set is rejected to avoid corrupting existing intervals.","triggerScenarios":"Calling SetInitialMin on a SequenceSet that already has entries (e.g. one loaded via Decode or previously added to).","commonSituations":"Reinitializing a consumer's pending/reserved sequence state that was already restored from disk, or double-initialization during setup code.","solutions":["Only call SetInitialMin right after creating the SequenceSet, before any adds or Decode","Check ss.IsEmpty() before calling SetInitialMin and skip if already populated","If you need to seed a minimum on a populated set, delete the set and rebuild it with the desired initial value"],"exampleFix":"// before\nss.SetInitialMin(min) // panics-free but errors if ss already restored\n// after\nif ss.IsEmpty() {\n    ss.SetInitialMin(min)\n}","handlingStrategy":"validation","validationCode":"if !ss.IsEmpty() {\n    // already initialized; skip seeding\n} else {\n    ss.SetInitialMin(min)\n}","typeGuard":null,"tryCatchPattern":"err := ss.SetInitialMin(min)\nif errors.Is(err, avl.ErrSetNotEmpty) {\n    log.Debug(\"sequence set already populated; skipping initial min\")\n}","preventionTips":["Call SetInitialMin only immediately after constructing the SequenceSet","Guard with IsEmpty() before seeding","Avoid re-running init logic on restored state"],"tags":["data-structure","state-management","jetstream","go"],"backgroundTag":"non-empty-state-initialization","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}