{"record":{"id":"8342831ffdd1e923","repo":"t8y2/dbx","slug":"etcd-invalid-s","errorCode":"ETCD_INVALID_%s","errorMessage":"ETCD_INVALID_%s: a positive integer is required","messagePattern":"ETCD_INVALID_(.+?): a positive integer is required","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd-go/kv.go","lineNumber":619,"sourceCode":"\treturn value\n}\n\nfunc longOrNull(params map[string]json.RawMessage, key string) *int64 {\n\traw := params[key]\n\tif len(raw) == 0 || string(raw) == \"null\" {\n\t\treturn nil\n\t}\n\tvar value int64\n\tif err := json.Unmarshal(raw, &value); err != nil {\n\t\treturn nil\n\t}\n\treturn &value\n}\n\nfunc requiredPositiveLong(params map[string]json.RawMessage, field string) (int64, error) {\n\tvalue := longOrNull(params, field)\n\tif value == nil || *value <= 0 {\n\t\treturn 0, fmt.Errorf(\"ETCD_INVALID_%s: a positive integer is required\", strings.ToUpper(field))\n\t}\n\treturn *value, nil\n}\n\nfunc requiredString(params map[string]json.RawMessage, field string) (string, error) {\n\tvalue := stringOrNull(params, field)\n\tif value == nil || *value == \"\" {\n\t\treturn \"\", fmt.Errorf(\"ETCD_%s_REQUIRED\", strings.ToUpper(field))\n\t}\n\treturn *value, nil\n}\n","sourceCodeStart":601,"sourceCodeEnd":631,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/kv.go#L601-L631","documentation":"requiredPositiveLong validates that a numeric request field is present and strictly positive. When the field is missing, null, zero, negative, or not a number, it throws a typed error whose code embeds the uppercased field name (e.g. ETCD_INVALID_TTL). This keeps malformed lease/compact requests from reaching etcd.","triggerScenarios":"leaseGet, leaseGrant, leaseKeepAlive, leaseRevoke, or compact called with params missing the required field, the field set to 0 or a negative number, or a non-numeric JSON value (longOrNull returns nil for non-numbers).","commonSituations":"Client omits \"TTL\" on a lease grant; a template variable interpolated as 0 or empty; sending \"TTL\": \"10\" as a string when a JSON number is required; default-initialized struct serialized with 0; compact called with rev=0.","solutions":["Inspect the error code (ETCD_INVALID_<FIELD>) to find the offending field and supply a positive integer JSON number (e.g. \"TTL\": 10).","Add client-side validation: reject value <= 0 before issuing the call.","If the field may legitimately be absent, use the optional variant instead of the required_* helper, or default it explicitly.","Check for string-typed numbers in the request payload and convert them to JSON numbers."],"exampleFix":"// before\n{\"TTL\": 0} // or field omitted\n// after\n{\"TTL\": 300}","handlingStrategy":"validation","validationCode":"func validatePositiveInt(params map[string]json.RawMessage, field string) error {\n\traw, ok := params[field]\n\tif !ok {\n\t\treturn fmt.Errorf(\"field %s is required\", field)\n\t}\n\tvar n int64\n\tif err := json.Unmarshal(raw, &n); err != nil {\n\t\treturn fmt.Errorf(\"field %s must be a JSON number\", field)\n\t}\n\tif n <= 0 {\n\t\treturn fmt.Errorf(\"field %s must be > 0\", field)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"ttl, err := leaseGrant(params)\nif err != nil {\n\tvar typed interface{ Code() string }\n\tif errors.As(err, &typed) && strings.HasPrefix(typed.Code(), \"ETCD_INVALID_\") {\n\t\treturn fmt.Errorf(\"bad request: %w\", err) // 400-style, do not retry\n\t}\n\treturn err\n}","preventionTips":["Validate required numeric params at the API boundary before dispatching to the driver.","Never send string-encoded numbers for long fields; ensure JSON number types.","Initialize defaults explicitly (e.g. TTL 0 -> a real default) instead of relying on zero values.","Surface the field name from the error code back to API callers in validation responses."],"tags":["validation","etcd","lease","parameters"],"backgroundTag":"invalid-parameter","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"}