{"record":{"id":"b60973cb6984e3d0","repo":"hyperledger/fabric","slug":"version-field-s-was-not-found","errorCode":null,"errorMessage":"version field %s was not found","messagePattern":"version field (.+?) was not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv.go","lineNumber":109,"sourceCode":"\tvalue              []byte\n\tversionAndMetadata string\n}\n\nfunc validateAndRetrieveFields(doc *couchDoc) (*couchDocFields, error) {\n\tjsonDoc := make(jsonValue)\n\tdecoder := json.NewDecoder(bytes.NewBuffer(doc.jsonValue))\n\tdecoder.UseNumber()\n\tif err := decoder.Decode(&jsonDoc); err != nil {\n\t\treturn nil, err\n\t}\n\n\tdocFields := &couchDocFields{}\n\tdocFields.id = jsonDoc[idField].(string)\n\tif jsonDoc[revField] != nil {\n\t\tdocFields.revision = jsonDoc[revField].(string)\n\t}\n\tif jsonDoc[versionField] == nil {\n\t\treturn nil, fmt.Errorf(\"version field %s was not found\", versionField)\n\t}\n\tdocFields.versionAndMetadata = jsonDoc[versionField].(string)\n\n\tdelete(jsonDoc, idField)\n\tdelete(jsonDoc, revField)\n\tdelete(jsonDoc, versionField)\n\n\tvar err error\n\tif doc.attachments == nil {\n\t\tdocFields.value, err = json.Marshal(jsonDoc)\n\t\treturn docFields, err\n\t}\n\tfor _, attachment := range doc.attachments {\n\t\tif attachment.Name == binaryWrapper {\n\t\t\tdocFields.value = attachment.AttachmentBytes\n\t\t}\n\t}\n\treturn docFields, err","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv.go#L91-L127","documentation":"couchdb stores a Fabric-internal 'version' field in every state document; validateAndRetrieveFields requires it to reconstruct versioned keys/values. When a document read from the CouchDB state database lacks the version field, this error is returned, meaning the document was not written by the ledger's expected format.","triggerScenarios":"couchDocToKeyValue reads a couchDoc whose decoded JSON has no 'version' field — e.g. a manually created CouchDB document, a document from a different Fabric version/format, or a corrupted/deleted field.","commonSituations":"Operators editing CouchDB documents directly (Fauxton/curl), restoring state DBs from partial backups, mixing databases created by incompatible Fabric releases, or placing application documents into the ledger's database.","solutions":["Remove the foreign/manually created document from the ledger database or move it to a separate database","Verify the state database was created by the same Fabric version; if not, re-create the ledger or run the appropriate data migration","Restore the ledger database from a valid backup that includes the internal 'version' fields"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func docHasVersion(doc map[string]interface{}) bool {\n    _, ok := doc[\"version\"]\n    return ok\n}","typeGuard":"func isLedgerWrittenDoc(jsonBytes []byte) bool {\n    var m map[string]interface{}\n    if json.Unmarshal(jsonBytes, &m) != nil { return false }\n    _, ok := m[\"version\"]\n    return ok\n}","tryCatchPattern":"kv, err := couchDocToKeyValue(doc)\nif err != nil {\n    return nil, fmt.Errorf(\"unexpected document in state DB (missing version field?): %w\", err)\n}","preventionTips":["Never hand-edit documents in the ledger's CouchDB database","Keep application data in separate CouchDB databases, not the ledger DB","Restore only from backups created by the same Fabric version","Monitor for external writes to ledger databases"],"tags":["couchdb","state-database","fabric-ledger","document-format"],"backgroundTag":"missing-version-field","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}