{"record":{"id":"46f55b1d57cae124","repo":"hyperledger/fabric","slug":"error-marshaling-chaincodeactionpayload","errorCode":null,"errorMessage":"error marshaling ChaincodeActionPayload","messagePattern":"error marshaling ChaincodeActionPayload","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":168,"sourceCode":"}\n\n// GetBytesChaincodeEvent gets the bytes of ChaincodeEvent\nfunc GetBytesChaincodeEvent(event *peer.ChaincodeEvent) ([]byte, error) {\n\tif event == nil {\n\t\treturn nil, errors.New(\"error marshaling ChaincodeEvent: proto: Marshal called with nil\")\n\t}\n\teventBytes, err := proto.Marshal(event)\n\treturn eventBytes, errors.Wrap(err, \"error marshaling ChaincodeEvent\")\n}\n\n// GetBytesChaincodeActionPayload get the bytes of ChaincodeActionPayload from\n// the message\nfunc GetBytesChaincodeActionPayload(cap *peer.ChaincodeActionPayload) ([]byte, error) {\n\tif cap == nil {\n\t\treturn nil, errors.New(\"error marshaling ChaincodeActionPayload: proto: Marshal called with nil\")\n\t}\n\tcapBytes, err := proto.Marshal(cap)\n\treturn capBytes, errors.Wrap(err, \"error marshaling ChaincodeActionPayload\")\n}\n\n// GetBytesProposalResponse gets proposal bytes response\nfunc GetBytesProposalResponse(pr *peer.ProposalResponse) ([]byte, error) {\n\tif pr == nil {\n\t\treturn nil, errors.New(\"error marshaling ProposalResponse: proto: Marshal called with nil\")\n\t}\n\trespBytes, err := proto.Marshal(pr)\n\treturn respBytes, errors.Wrap(err, \"error marshaling ProposalResponse\")\n}\n\n// GetBytesHeader get the bytes of Header from the message\nfunc GetBytesHeader(hdr *common.Header) ([]byte, error) {\n\tif hdr == nil {\n\t\treturn nil, errors.New(\"error marshaling Header: proto: Marshal called with nil\")\n\t}\n\tbytes, err := proto.Marshal(hdr)\n\treturn bytes, errors.Wrap(err, \"error marshaling Header\")","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L150-L186","documentation":"This is the wrapped error from proto.Marshal inside GetBytesChaincodeActionPayload when serialization of a non-nil payload fails. errors.Wrap appends the 'error marshaling ChaincodeActionPayload' context to the underlying proto error.","triggerScenarios":"proto.Marshal failing on a non-nil *peer.ChaincodeActionPayload — typically an inconsistent proto runtime/codegen pair or a struct built from invalid decoded bytes rather than through the generated API.","commonSituations":"Version skew between fabric-protos-go and the proto/gogo runtime after a dependency upgrade, corrupted transaction payloads parsed from untrusted input.","solutions":["Use errors.Cause(err) to surface the root proto error.","Align versions of github.com/hyperledger/fabric-protos-go and gogo/protobuf in go.mod, then rebuild.","Rebuild the payload from a parsed ProposalResponse instead of manual field assembly.","If the pointer was actually nil, apply the nil guard from the 'Marshal called with nil' variant."],"exampleFix":"// before\ncapBytes, err := protoutil.GetBytesChaincodeActionPayload(cap)\nif err != nil {\n    return nil, err\n}\n// after\ncapBytes, err := protoutil.GetBytesChaincodeActionPayload(cap)\nif err != nil {\n    return nil, errors.Wrap(errors.Cause(err), \"cannot serialize ChaincodeActionPayload\")\n}","handlingStrategy":"try-catch","validationCode":"if cap == nil {\n    return nil, errors.New(\"ChaincodeActionPayload is nil\")\n}","typeGuard":"func isSerializableCAP(cap *peer.ChaincodeActionPayload) bool {\n    return cap != nil\n}","tryCatchPattern":"capBytes, err := protoutil.GetBytesChaincodeActionPayload(cap)\nif err != nil {\n    return nil, errors.Wrap(errors.Cause(err), \"ChaincodeActionPayload serialization failed\")\n}","preventionTips":["Log the underlying cause (errors.Cause) for wrapped marshal failures.","Keep generated protobuf packages and the runtime on compatible versions.","Avoid hand-assembling payload structs from raw bytes; parse via the generated API."],"tags":["grpc","protobuf","serialization","transaction","hyperledger-fabric"],"backgroundTag":"proto-marshal-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"}