{"record":{"id":"d93d010ac034cab1","repo":"t8y2/dbx","slug":"etcd-v2-cas-unsupported","errorCode":"ETCD_V2_CAS_UNSUPPORTED","errorMessage":"ETCD_V2_CAS_UNSUPPORTED: the etcd v2 API cannot compare createdIndex; use expectedModRevision","messagePattern":"ETCD_V2_CAS_UNSUPPORTED: the etcd v2 API cannot compare createdIndex; use expectedModRevision","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd2-go/kv.go","lineNumber":209,"sourceCode":"\texpectedModRevision := longOrNull(params, \"expectedModRevision\")\n\texpectedCreateRevision := longOrNull(params, \"expectedCreateRevision\")\n\tttlValue := longOrNull(params, \"ttl\")\n\tpreserveLease := boolOrDefault(params, \"preserveLease\", false)\n\n\tleaseValue := longOrNull(params, \"lease\")\n\thasLease := leaseValue != nil\n\thasTtl := ttlValue != nil\n\tif (hasLease && hasTtl) || (preserveLease && (hasLease || hasTtl)) {\n\t\treturn nil, errors.New(\"lease, ttl, and preserveLease cannot be specified together\")\n\t}\n\tif hasLease {\n\t\treturn nil, errors.New(\"ETCD_V2_LEASE_UNSUPPORTED: the etcd v2 API has no lease objects; use ttl instead\")\n\t}\n\tif preserveLease {\n\t\treturn nil, errors.New(\"ETCD_V2_LEASE_UNSUPPORTED: the etcd v2 API has no lease objects; use ttl instead\")\n\t}\n\tif expectedCreateRevision != nil && *expectedCreateRevision != 0 {\n\t\treturn nil, errors.New(\"ETCD_V2_CAS_UNSUPPORTED: the etcd v2 API cannot compare createdIndex; use expectedModRevision\")\n\t}\n\tif hasTtl && *ttlValue <= 0 {\n\t\treturn nil, errors.New(\"ttl must be a positive integer\")\n\t}\n\n\tform := url.Values{}\n\tform.Set(\"value\", value)\n\tif hasTtl {\n\t\tform.Set(\"ttl\", strconv.FormatInt(*ttlValue, 10))\n\t}\n\tif expectedModRevision != nil {\n\t\tform.Set(\"prevIndex\", strconv.FormatInt(*expectedModRevision, 10))\n\t}\n\tif expectedCreateRevision != nil && *expectedCreateRevision == 0 {\n\t\tform.Set(\"prevExist\", \"false\")\n\t}\n\n\tctx, cancel := s.beginOperation()","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd2-go/kv.go#L191-L227","documentation":"The v2 API's compare-and-swap can only compare modifiedIndex, not createdIndex. A put that supplies expectedCreateRevision with a non-zero value asks for a comparison v2 cannot perform, so it is rejected with this code; the message points to expectedModRevision as the supported alternative.","triggerScenarios":"Calling put with expectedCreateRevision set to a non-zero value against an etcd v2 session.","commonSituations":"Porting optimistic-concurrency code from v3 (where create_revision compare exists); generic clients that always send both expected fields; tests copied from v3 suites.","solutions":["Replace expectedCreateRevision with expectedModRevision","Drop the CAS field if create-revision semantics are not essential","Use the v3 driver if compare-on-createRevision is required"],"exampleFix":"// before\n{ \"key\":\"k\", \"value\":\"v\", \"expectedCreateRevision\": 42 }\n// after\n{ \"key\":\"k\", \"value\":\"v\", \"expectedModRevision\": 42 }","handlingStrategy":"validation","validationCode":"if expectedCreateRevision != nil && *expectedCreateRevision != 0 {\n\treturn errors.New(\"etcd v2 CAS supports only expectedModRevision\")\n}","typeGuard":null,"tryCatchPattern":"_, err := session.handle(ctx, \"put\", params)\nif err != nil && strings.Contains(err.Error(), \"ETCD_V2_CAS_UNSUPPORTED\") {\n\treturn fmt.Errorf(\"rewrite CAS to expectedModRevision or use the v3 driver\")\n}","preventionTips":["Use expectedModRevision for all v2 optimistic concurrency","Do not blindly forward v3-style CAS fields to v2 sessions","Read the mod_revision from get results and use it for compares","Pin v3-dependent workflows to the v3 driver via a capability flag"],"tags":["etcd","cas","api-version","unsupported"],"backgroundTag":"api-not-supported","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"}