{"record":{"id":"9531612c03ec471f","repo":"hyperledger/fabric","slug":"error-unmarshalling-chaincodeactionpayload","errorCode":null,"errorMessage":"error unmarshalling ChaincodeActionPayload","messagePattern":"error unmarshalling ChaincodeActionPayload","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/unmarshalers.go","lineNumber":165,"sourceCode":"// UnmarshalProposal unmarshals bytes to a Proposal\nfunc UnmarshalProposal(propBytes []byte) (*peer.Proposal, error) {\n\tprop := &peer.Proposal{}\n\terr := proto.Unmarshal(propBytes, prop)\n\treturn prop, errors.Wrap(err, \"error unmarshalling Proposal\")\n}\n\n// UnmarshalTransaction unmarshals bytes to a Transaction\nfunc UnmarshalTransaction(txBytes []byte) (*peer.Transaction, error) {\n\ttx := &peer.Transaction{}\n\terr := proto.Unmarshal(txBytes, tx)\n\treturn tx, errors.Wrap(err, \"error unmarshalling Transaction\")\n}\n\n// UnmarshalChaincodeActionPayload unmarshals bytes to a ChaincodeActionPayload\nfunc UnmarshalChaincodeActionPayload(capBytes []byte) (*peer.ChaincodeActionPayload, error) {\n\tcap := &peer.ChaincodeActionPayload{}\n\terr := proto.Unmarshal(capBytes, cap)\n\treturn cap, errors.Wrap(err, \"error unmarshalling ChaincodeActionPayload\")\n}\n\n// 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) {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/unmarshalers.go#L147-L183","documentation":"UnmarshalChaincodeActionPayload wraps proto.Unmarshal failures for peer.ChaincodeActionPayload bytes with this message. It is thrown when the input bytes are not a valid ChaincodeActionPayload protobuf. Typically the caller extracted the wrong slice of the transaction payload (e.g. did not unwrap the TransactionActions first).","triggerScenarios":"Calling UnmarshalChaincodeActionPayload with the full payload instead of Transaction.Actions[0].Payload, empty/nil bytes, truncated CAP bytes, or bytes produced by mismatched proto versions.","commonSituations":"Transaction validators (Validate, validateEndorserTransaction) processing a tampered or malformed block, or tooling that unpacks the wrong nesting level of an endorser transaction.","solutions":["Confirm the input is Transaction.Actions[i].Payload (ChaincodeActionPayload level), not the outer Payload or the ProposalResponsePayload","Check the byte slice is non-empty and not truncated before calling","Verify fabric-protos version alignment between writer and reader of the bytes","Handle the error path gracefully: treat the transaction as invalid (as Fabric validation code does) rather than retrying"],"exampleFix":"// before\ncap, err := protoutil.UnmarshalChaincodeActionPayload(payloadBytes) // wrong level\n// after\ntx, _ := protoutil.UnmarshalTransaction(env.Payload)\nif len(tx.Actions) == 0 { return errors.New(\"no transaction actions\") }\ncap, err := protoutil.UnmarshalChaincodeActionPayload(tx.Actions[0].Payload)","handlingStrategy":"validation","validationCode":"func extractCAP(tx *peer.Transaction, idx int) ([]byte, bool) {\n    if tx == nil || idx >= len(tx.Actions) || len(tx.Actions[idx].Payload) == 0 {\n        return nil, false\n    }\n    return tx.Actions[idx].Payload, true\n}","typeGuard":"func safeUnmarshalCAP(b []byte) (cap *peer.ChaincodeActionPayload, ok bool) {\n    cap, err := protoutil.UnmarshalChaincodeActionPayload(b)\n    return cap, err == nil && cap != nil\n}","tryCatchPattern":"cap, err := protoutil.UnmarshalChaincodeActionPayload(actionBytes)\nif err != nil {\n    return nil, status.Errorf(codes.InvalidArgument, \"malformed chaincode action payload: %v\", err)\n}","preventionTips":["Drill down to Transaction.Actions[i].Payload before unmarshalling","Check the action exists and its payload is non-empty","Treat unmarshal failure as transaction invalidity, matching peer validation semantics","Pin fabric-protos versions across producer and consumer"],"tags":["protobuf","unmarshal","fabric","chaincode-action-payload"],"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"}