{"record":{"id":"8a2d0c00cac3ae94","repo":"hyperledger/fabric","slug":"error-marshaling-chaincodeactionpayload-proto-ma","errorCode":null,"errorMessage":"error marshaling ChaincodeActionPayload: proto: Marshal called with nil","messagePattern":"error marshaling ChaincodeActionPayload: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":165,"sourceCode":"\t}\n\tresBytes, err := proto.Marshal(res)\n\treturn resBytes, errors.Wrap(err, \"error marshaling Response\")\n}\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\")","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L147-L183","documentation":"GetBytesChaincodeActionPayload serializes a *peer.ChaincodeActionPayload. A nil pointer cannot be marshaled by proto.Marshal, so the function returns this explicit error naming the message type. Callers use the result when assembling signed transactions.","triggerScenarios":"Calling protoutil.GetBytesChaincodeActionPayload(nil), or passing cap extracted from a Transaction action that is missing/nil (as in CreateSignedTx, prepareTransaction, createSignedTxTwoActions when actions are absent).","commonSituations":"Building a signed transaction from proposal responses where the payload action was never populated, or a ProposalResponse.Payload failed to unmarshal into ChaincodeActionPayload earlier in the flow.","solutions":["Nil-check the ChaincodeActionPayload before calling GetBytesChaincodeActionPayload.","Verify the earlier GetProposalResponsePayload/UnmarshalChaincodeActionPayload step succeeded and produced a non-nil result.","Ensure each ProposalResponse passed to CreateSignedTx has a valid Payload.","In tests, construct &peer.ChaincodeActionPayload{...} before invoking."],"exampleFix":"// before\ncapBytes, err := protoutil.GetBytesChaincodeActionPayload(cap)\n// after\nif cap == nil {\n    return nil, errors.New(\"missing ChaincodeActionPayload for transaction\")\n}\ncapBytes, err := protoutil.GetBytesChaincodeActionPayload(cap)","handlingStrategy":"validation","validationCode":"if cap == nil {\n    return nil, errors.New(\"cannot build transaction: ChaincodeActionPayload is nil\")\n}","typeGuard":"func hasActionPayload(pResp *peer.ProposalResponse) bool {\n    return pResp != nil && pResp.Payload != nil\n}","tryCatchPattern":"capBytes, err := protoutil.GetBytesChaincodeActionPayload(cap)\nif err != nil {\n    return nil, errors.Wrap(err, \"ChaincodeActionPayload serialization failed\")\n}","preventionTips":["Verify GetPayloadResponses/UnmarshalChaincodeActionPayload succeeded before building the tx.","Validate every ProposalResponse has a non-nil Payload before CreateSignedTx.","Reject endorsement sets with missing actions early instead of at serialization time."],"tags":["grpc","protobuf","nil-pointer","transaction","hyperledger-fabric"],"backgroundTag":"proto-marshal-nil-message","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"}