{"record":{"id":"bd17cc8dd5dcca68","repo":"hyperledger/fabric","slug":"error-unmarshalling-kvrwset","errorCode":null,"errorMessage":"error unmarshalling KVRWSet","messagePattern":"error unmarshalling KVRWSet","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":186,"sourceCode":"// UnmarshalChaincodeProposalPayload unmarshals bytes to a ChaincodeProposalPayload\nfunc UnmarshalChaincodeProposalPayload(bytes []byte) (*peer.ChaincodeProposalPayload, error) {\n\tcpp := &peer.ChaincodeProposalPayload{}\n\terr := proto.Unmarshal(bytes, cpp)\n\treturn cpp, errors.Wrap(err, \"error unmarshalling ChaincodeProposalPayload\")\n}\n\n// UnmarshalTxReadWriteSet unmarshals bytes to a TxReadWriteSet\nfunc UnmarshalTxReadWriteSet(bytes []byte) (*rwset.TxReadWriteSet, error) {\n\trws := &rwset.TxReadWriteSet{}\n\terr := proto.Unmarshal(bytes, rws)\n\treturn rws, errors.Wrap(err, \"error unmarshalling TxReadWriteSet\")\n}\n\n// UnmarshalKVRWSet unmarshals bytes to a KVRWSet\nfunc UnmarshalKVRWSet(bytes []byte) (*kvrwset.KVRWSet, error) {\n\trws := &kvrwset.KVRWSet{}\n\terr := proto.Unmarshal(bytes, rws)\n\treturn rws, errors.Wrap(err, \"error unmarshalling KVRWSet\")\n}\n\n// UnmarshalHashedRWSet unmarshals bytes to a HashedRWSet\nfunc UnmarshalHashedRWSet(bytes []byte) (*kvrwset.HashedRWSet, error) {\n\thrws := &kvrwset.HashedRWSet{}\n\terr := proto.Unmarshal(bytes, hrws)\n\treturn hrws, errors.Wrap(err, \"error unmarshalling HashedRWSet\")\n}\n\n// UnmarshalSignaturePolicy unmarshals bytes to a SignaturePolicyEnvelope\nfunc UnmarshalSignaturePolicy(bytes []byte) (*common.SignaturePolicyEnvelope, error) {\n\tsp := &common.SignaturePolicyEnvelope{}\n\terr := proto.Unmarshal(bytes, sp)\n\treturn sp, errors.Wrap(err, \"error unmarshalling SignaturePolicyEnvelope\")\n}\n\n// UnmarshalPayloadOrPanic unmarshals bytes to a Payload structure or panics\n// on error","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L168-L204","documentation":"UnmarshalKVRWSet wraps proto.Unmarshal failures for kvrwset.KVRWSet bytes with this message. It fires when the bytes are not a valid KVRWSet protobuf — usually because the input was the outer TxReadWriteSet or corrupted data. Only rwsetDifference calls it, in key-value RW set comparison.","triggerScenarios":"Passing TxReadWriteSet bytes instead of the per-namespace KVRWSet ( Rwset field), empty bytes, truncated results, or KVRead/KVWrite data produced by a mismatched proto version.","commonSituations":"RW set diff tools comparing state deltas per namespace, privdata validation utilities, or tests with manually constructed byte slices.","solutions":["Confirm the input is the KVRWSet for a single namespace (TxReadWriteSet.NsRwSets[i].Rwset), not the outer message","Guard against empty/nil byte slices before unmarshalling","Check that both sides of the comparison serialize with the same fabric-protos version","Return a descriptive comparison failure when unmarshal fails instead of letting the wrapped error propagate ambiguously"],"exampleFix":"// before\nrws, err := protoutil.UnmarshalKVRWSet(txRwSetBytes) // wrong level\n// after\nrws, err := protoutil.UnmarshalKVRWSet(nsRwSet.Rwset)\nif err != nil { return fmt.Errorf(\"namespace %s: %w\", nsRwSet.Namespace, err) }","handlingStrategy":"validation","validationCode":"func extractKVRWSetBytes(ns *rwset.NsReadWriteSet) ([]byte, bool) {\n    if ns == nil || len(ns.Rwset) == 0 { return nil, false }\n    return ns.Rwset, true\n}","typeGuard":"func safeUnmarshalKVRWS(b []byte) (rws *kvrwset.KVRWSet, ok bool) {\n    rws, err := protoutil.UnmarshalKVRWSet(b)\n    return rws, err == nil && rws != nil\n}","tryCatchPattern":"rws, err := protoutil.UnmarshalKVRWSet(nsRwSet.Rwset)\nif err != nil {\n    return fmt.Errorf(\"namespace %s has undecodable KVRWSet: %w\", nsRwSet.Namespace, err)\n}","preventionTips":["Use the per-namespace NsRwSets[i].Rwset field, not the outer TxReadWriteSet bytes","Include namespace/collection context in any wrapped error for diagnosis","Guard empty slices before unmarshalling","Verify both comparison inputs were marshalled with the same protos"],"tags":["protobuf","unmarshal","fabric","kv-rwset"],"backgroundTag":"proto-unmarshal-failed","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"}