{"record":{"id":"f76d978a70239982","repo":"t8y2/dbx","slug":"id-must-be-a-positive-integer-or-0","errorCode":null,"errorMessage":"id must be a positive integer or 0","messagePattern":"id must be a positive integer or 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd-go/lease.go","lineNumber":265,"sourceCode":"\t\tkeys = append(keys, bytesObject(key))\n\t}\n\treturn map[string]any{\n\t\t\"id\":         unsignedLongString(int64(response.ID)),\n\t\t\"ttl\":        response.TTL,\n\t\t\"grantedTtl\": response.GrantedTTL,\n\t\t\"keys\":       keys,\n\t\t\"truncated\":  len(response.Keys) > maxLeaseAttachedKeys,\n\t}, nil\n}\n\nfunc (s *etcdSession) leaseGrant(params map[string]json.RawMessage) (any, error) {\n\tttl, err := requiredPositiveLong(params, \"ttl\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\trequestedID := longOrNull(params, \"id\")\n\tif requestedID != nil && *requestedID < 0 {\n\t\treturn nil, errors.New(\"id must be a positive integer or 0\")\n\t}\n\tclient, err := s.activeClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tctx, cancel := s.beginOperation()\n\tdefer s.endOperation(cancel)\n\tvar grantedID clientv3.LeaseID\n\tvar grantedTTL int64\n\tif requestedID == nil || *requestedID == 0 {\n\t\tresponse, err := client.Lease.Grant(ctx, ttl)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tgrantedID = response.ID\n\t\tgrantedTTL = response.TTL\n\t} else {\n\t\tleaseClient := etcdserverpb.NewLeaseClient(client.ActiveConnection())","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/lease.go#L247-L283","documentation":"leaseGrant validates the optional requested lease ID before contacting the cluster: after requiring a positive \"ttl\", it reads \"id\" with longOrNull and rejects negative values with \"id must be a positive integer or 0\". etcd requires lease IDs to be positive (or 0/omitted so the server allocates one), so the library enforces this client-side to fail fast.","triggerScenarios":"Calling leaseGrant with params {\"id\": -1, ...} (any negative integer) while \"ttl\" is a positive value — checked at lease.go:265. Omitting id or passing id=0 is allowed (server assigns an ID).","commonSituations":"Constructing the id from parsed input where -1 is used as a 'not set' marker; porting code from another system where negative IDs are reserved; arithmetic underflow producing a negative ID.","solutions":["Pass id as 0 or omit it entirely to let etcd allocate a fresh lease ID.","Clamp/reject negative IDs at the call site before invoking leaseGrant.","If you need a specific ID, choose a positive integer you know is unused on the cluster."],"exampleFix":"// before\nagent.call(\"lease_grant\", {\"ttl\": 30, \"id\": -1})\n\n// after: let the server pick an ID\nagent.call(\"lease_grant\", {\"ttl\": 30, \"id\": 0})","handlingStrategy":"validation","validationCode":"if id < 0 {\n    return errors.New(\"leaseGrant id must be >= 0; use 0 to let the server allocate\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 0 (or omit 'id') for server-allocated lease IDs.","Never use -1 as a 'not set' sentinel for numeric lease IDs.","Validate ID sign at the config-parsing layer, not at call time."],"tags":["etcd","validation","lease","invalid-argument"],"backgroundTag":"invalid-parameter-value","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}